#38013 [NEW]: pass by reference with assignment

From: Date: Wed, 05 Jul 2006 08:33:51 +0000
Subject: #38013 [NEW]: pass by reference with assignment
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-99107@lists.php.net to get a copy of this message
From: flex at city dot ee Operating system: Linux PHP version: 5.1.4 PHP Bug Type: Variables related Bug description: pass by reference with assignment Description: ------------ When passing in variable which gets assigned in function call, PHP wrongly thinks it got something other than variable: function test(&$a) { $a = 2; } // take $a as reference test($m = 5); // should mean assign 5 to $m and _then_ pass in variable $m Instead it looks like php sends scalar 5 to function (and throws E_STRICT error), which is plainly wrong. Or is the documentation wrong about operator precedence? Really: <?php $m=1;test($m); ?> should mean exactly same as <?php <?php test($m=1); ?>. Currently it does not and IMHO this is very counter-productive to PHP's KISS principle. Especially that last S. By the way I know there are tons of similar bug reports marked Bogus. But please think about this report once more. Also you should consider the fact that the 'expected result' shown in this bug report is not hand-written but obtained from PHP 4.4.2 - and this only means serious BC problem. Reproduce code: --------------- <?php function test(&$a) { $a = 2; } $m = 1; test($m); var_dump($m); test($m = 1); var_dump($m); ?> Expected result: ---------------- int(2) int(2) Actual result: -------------- int(2) int(1) -- Edit bug report at http://bugs.php.net/?id=38013&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38013&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38013&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38013&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38013&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38013&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38013&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38013&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38013&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38013&r=support Expected behavior: http://bugs.php.net/fix.php?id=38013&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38013&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38013&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38013&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38013&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38013&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38013&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38013&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38013&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38013&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38013&r=mysqlcfg

« previous php.bugs (#99107) next »