ID: 43984
User updated by: robin_fernandes at uk dot ibm dot com
Reported By: robin_fernandes at uk dot ibm dot com
Status: Open
Bug Type: Scripting Engine problem
Operating System: Windows
PHP Version: 5.2.5
New Comment:
Note that if the variable is defined, it is correctly passed by
reference whether or not the parens are present:
<?php
function f(&$ref) {
$ref='changed';
}
echo "\nPass defined variable by ref with parentheses:\n";
$c = null;
f( ($c) );
var_dump($c);
?>
Prints:
Pass defined variable by ref with parentheses:
string(7) "changed"
Previous Comments:
------------------------------------------------------------------------
[2008-01-30 18:00:49] robin_fernandes at uk dot ibm dot com
Description:
------------
Passing an undefined variable by reference causes that variable to be
implicitly defined. However, this is not the case if the argument is
inside parentheses.
This is reproducible on php5.2.5 as well as php5.3 and php6 snaps.
Reproduce code:
---------------
<?php
function f(&$ref) {
$ref='changed';
}
echo "Pass undefined variable by ref:\n";
f( $a );
var_dump($a);
echo "\nPass undefined variable by ref with parentheses:\n";
f( ($b) );
var_dump($b);
?>
Expected result:
----------------
Pass undefined variable by ref:
string(7) "changed"
Pass undefined variable by ref with parentheses:
string(7) "changed"
Actual result:
--------------
Pass undefined variable by ref:
string(7) "changed"
Pass undefined variable by ref with parentheses:
Notice: Undefined variable: b in %s on line 11
Strict Standards: Only variables should be passed by reference in %s on
line 11
Notice: Undefined variable: b in %s on line 12
NULL
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43984&edit=1