[wp-hackers] PHP4->5 upgrade heads up && another change of topic---

Angsuman Chakraborty angsuman at taragana.com
Fri Jul 14 18:12:37 GMT 2006


> by the way, have you (or anyone on the list) been using or upgraded to MySQL
5.xx branch ?  Any issues/quirks, etc ?

I did. No problems with WordPress or Mambo / Joomla as far as I could see.

Best,
Angsuman

-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com]On Behalf Of Christopher
J. Hradil
Sent: Friday, July 14, 2006 5:33 AM
To: wp-hackers at lists.automattic.com
Subject: RE: [wp-hackers] PHP4->5 upgrade heads up && another change of
topic---
Importance: Low


I've purposely avoided php5 for now for a number of reasons, but this is
useful info, as I have seen a similar problem with a couple of folks using
php5, and I think this might be a good "quick fix". thanks...

by the way, have you (or anyone on the list) been using or upgraded to MySQL
5.xx branch ?  Any issues/quirks, etc ?

I have a big project coming up that I'd like to be using 5.xx for but I'm a
little afraid to upgrade my dev box (which I have my live personal site on)
because it's also going to mean rebuilding php and a couple of other things
on the box. 

..chris 


/**************************************
Christopher J. Hradil
chradil at comcast.net
http://www.hradil.us
973-809-4606
**************************************/


-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Brian Layman
Sent: Thursday, July 13, 2006 5:56 PM
To: wp-hackers at lists.automattic.com
Subject: [wp-hackers] PHP4->5 upgrade heads up

On a related topic, I've been meaning to mention the widgets problem I'd
discussed with Andy Skelton.  In the end it was related to the change in
array_merge between PHP4 and PHP5 and could occur in anyone's code.  So, if
someone missed this array_merge change, I thought a public post might be
beneficial...  

PHP5's array_merge now blows up on non-array variables.  It seems some PHP
array functions, specifically array_slice, return non-array (unset)
variables.  So, in short, an array_merge that works in php4 may not work in
php5 unless you follow the same convention Mark Jaquith recommended when he
said "cast to array before foreach".  

If a variable's content hasn't already been verified as containing an array,
you should cast to array before using it in an array_merge.  
That could look like this:
  $result = array_merge(array('a'=>1,'b'=>2), (array) $second);

Details on the change can of course be seen here:
http://us2.php.net/array_merge

I'm sure this is old news for some. So, unless you want details of what we
changed, you probably won't care to read on.

---- 

For a practical example, we could look at the now fixed issue from
widgets.php.

An array slice was done in a fashion similar to this:
  $registered_widgets[$name]['params'] => array_slice(func_get_args(), 2)

We are assuming that the problem arose when the 2 argument was defaulted to
''.

The line that actually blew up was this one:
 $params = array_merge(array($sidebar),
$registered_widgets[$name]['params']);

The error was:
"Warning: array_merge() [function.array-merge]: Argument #2 is not an array
in ./wp-content/plugins/widgets/widgets.php on line 154"

There is nothing that indicates array_slice changed between 4 and 5.  So, it
appears the only difference was in array_merge.  Wrapping the error line in
an "if (is_array($registered_widgets[$name]['params']))" solved the problem,
but it was not the fix we used.

I remembered Mark's coding style suggestion for foreach in
(http://comox.textdrive.com/pipermail/wp-hackers/2006-July/006930.html) and
applying it solved the problem in a simpler fashion.  Andy checked in this
new line:
  $params = array_merge(array($sidebar), (array)
$registered_widgets[$name]['params']);

FYI, we'd tried this first:
  $registered_widgets[$name]['params'] => (array)
array_slice(func_get_args(), 2) but it had no affect.

-

I looked at every instance of array_merge in the 2.03 code, and it seems
that all of them are in places where the parameters are guaranteed to have
either a value or array() specified.  So, this is mostly a heads up to
plugin authors.  I haven't done any examination of the plugin code base.

_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list