From:             Ultrasick at gmx dot de
Operating system: probably any
PHP version:      5.2.6
PHP Bug Type:     Scripting Engine problem
Bug description:  array_walk ignores to pass reference if & is in function 
definition at userdata

Description:
------------
The function "array_walk" ignores to pass the reference and passes the
content instead for the parameter "userdata" if the "&" isn't written
inside the "array_walk()" but inside the function definition ("function
somename(&$value, &$key, &$userdata)"). This doesn't work for the
"userdata"-parameter but it does work for the "value" and the
"key"-parameter.

Have a look at the code at the bottom and the expected and the actual
result. Now compare what would happen if you would call "my_function"
manually by using

my_function($any_value, $any_key, $my_variable);
echo $my_variable;

and then using

my_function($any_value, $any_key, &$my_variable);
echo $my_variable;

In both cases $my_variable would be increased, of course.

So in my oppinion the userdata-problem it's not just inconsistency. It's a
bug because a part of the function definition is beeing ignored.

Reproduce code:
---------------
<?
function my_function(&$value, &$key, &$userdata){
        $userdata++;
}

$my_array = array('one', 'two', 'three');
$my_variable = 1;

array_walk($my_array, 'my_function', $my_variable);
echo $my_variable;

echo '<p><hr></p>';

array_walk($my_array, 'my_function', &$my_variable);
echo $my_variable;
?>

Expected result:
----------------
expected output:

4
-----------
4

Actual result:
--------------
actual output:

1
-----------
4

-- 
Edit bug report at http://bugs.php.net/?id=45780&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=45780&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=45780&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=45780&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=45780&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=45780&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=45780&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=45780&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=45780&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=45780&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=45780&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=45780&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=45780&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=45780&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=45780&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=45780&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=45780&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=45780&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=45780&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=45780&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=45780&r=mysqlcfg

Reply via email to