From:             [EMAIL PROTECTED]
Operating system: Windows
PHP version:      4.2.3
PHP Bug Type:     Arrays related
Bug description:  'array_walk()' violates recommended 
'allow_call_time_pass_reference=Off'

The PHP manual contains the following note about 'array_walk()':

   Note: 
   If func needs to be working with the actual values of the array,
specify 
        that the first parameter of func should be passed by reference. Then any

        changes made to those elements will be made in the array itself. 

So if you want to let 'array_walk()' pass the third parameter by
reference, 
you're inclined to specify that the third parameter of func should be
passed by 
reference.  In the example underneath, the notation '&$userData' is used
to 
specify so:

   function PrepareBowl($value, $key, &$userData) {
     print 'Mixed so far... ' . ($userData .= "$value ") . "<br>\n";
   }
 
   $ingredients = array('peach', 'cherry', 'alchohol');
   $bowl = '';
   array_walk($ingredients, 'PrepareBowl', $bowl);
   print "Bowl: $bowl";

This doesn't work however; '$assembly' will not be passed by reference and
the 
output will be an empty 'bowl':

   Mixed so far... peach 
   Mixed so far... peach cherry 
   Mixed so far... peach cherry alchohol 
   Bowl: 

Only when you use the '&' notation within 'array_walk()' to specify that
the 
third parameter should be passed by reference:

   array_walk($ingredients, 'PrepareBowl', &$bowl);

the output will be as expected:

   Mixed so far... peach 
   Mixed so far... peach cherry 
   Mixed so far... peach cherry alchohol 
   Bowl: peach cherry alchohol 

but, using the recommended php.ini setting
'allow_call_time_pass_reference=Off',
you'll receive the warning:

   Warning: Call-time pass-by-reference has been deprecated - argument
        passed by value; If you would like to pass it by reference, modify the 
        declaration of array_walk(). If you would like to enable call-time 
        pass-by-reference, you can set allow_call_time_pass_reference to true in

        your INI file. However, future versions may not support this any longer.

This looks the same like bug 4116 (http://bugs.php.net/bug.php?id=4116),
posted Apr 12, 2000.  Although this bug is closed with a reply that it
works like the 
replier think it should work, this doesn't seem logic to me because the
first 
parameter *is* passed by reference without specifying; try:

   array_walk(array('peach', 'cherry', 'alchohol'), 'PrepareBowl',
&$bowl);

and you'll receive:

   Fatal error: Only variables can be passed by reference ...

Furthermore, I can't see much use of passing a third variable to
'array_walk()'
by value, modify it by passing it to func by reference ... without
receiving 
back the modified variable.

Would it be a suggestion to let 'array_walk()' receive the third parameter
by 
reference if specified so in the receiving func?  This would be in line
with
the behaviour of the first parameter to func.


Freddy Vulto
-- 
Edit bug report at http://bugs.php.net/?id=19699&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=19699&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=19699&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=19699&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=19699&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=19699&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=19699&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=19699&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=19699&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=19699&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=19699&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=19699&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=19699&r=dst

Reply via email to