[wp-trac] [WordPress Trac] #13757: Passing functions as call by ref parameter should be avoided

WordPress Trac wp-trac at lists.automattic.com
Mon Jun 7 11:17:27 UTC 2010


#13757: Passing functions as call by ref parameter should be avoided
--------------------------+-------------------------------------------------
 Reporter:  TobiasBg      |       Owner:             
     Type:  defect (bug)  |      Status:  new        
 Priority:  normal        |   Milestone:  3.0        
Component:  General       |     Version:             
 Severity:  normal        |    Keywords:  needs-patch
--------------------------+-------------------------------------------------
 I recently had a bug report for a plugin, where script execution was
 stopped at an avoidable warning.

 The problem was a call similar to
 {{{
 $my_array = array( ... );
 $last_element_index = array_pop( array_keys( $my_array ) );
 }}}

 The reason for the issue is that the parameter for {{{array_pop()}}} is
 passed as a call by reference parameter. This leads to a problem here,
 because {{{array_keys( $my_array )}}} is not a variable that could be
 changed during the call by reference process (in this case, the last
 element can not be removed from the array).
 This raises a warning by PHP (also documented at www.php.net/array_pop),
 and there are hosts that seem to be stopping PHP execution at such
 warning.

 Fixing the issue is very easy by adding a variable:
 {{{
 $my_array = array( ... );
 $_my_array_keys = array_keys( $my_array );
 $last_element_index = array_pop( $_my_array_keys );
 }}}

 As I had this issue in my plugin, I also grep'ed WP core and found two
 instances of {{{array_pop( array_keys() )}}}:

 - admin-ajax.php (line 893)

 - ms-edit.php (line 107)

 With {{{array_pop( explode() )}}}:

 - wp-app.php (line 226)


 With {{{array_pop( split() )}}}:

 - atomlib.php (lines 151 and 230)

 There are more functions (especially within {{{array_*}}}) that are
 affected, and that should be checked on whether a function call is passed
 where a call by ref parameter is expected.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/13757>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list