#38808 [Asn->Csd]: "maybe ref" issue for current() and others

From: Date: Tue, 26 Sep 2006 11:26:31 +0000
Subject: #38808 [Asn->Csd]: "maybe ref" issue for current() and others
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-102695@lists.php.net to get a copy of this message
ID: 38808 Updated by: dmitry@php.net Reported By: dev at ioncube dot com -Status: Assigned +Status: Closed Bug Type: Variables related Operating System: Any PHP Version: 5.1.6 Assigned To: dmitry New Comment: Fixed in CVS HEAD and PHP_5_2. Previous Comments: ------------------------------------------------------------------------ [2006-09-25 13:05:51] tony2001@php.net Dmitry, any ideas? ------------------------------------------------------------------------ [2006-09-14 11:25:20] dev at ioncube dot com "The point is that whether to send a parameter by ref or not is determined in _COMPILE TIME_." Correct :) Prior to 5.1, whether a function accepted a value by reference or value was a boolean decision, and the code in the executor, (which is still there), would promote the passed variable to by reference if the function required it. This is how and why the function next() would still work in this example for even a dynamic call because the parameter must be a reference, and that logic still works. As of 5.1.0 the test became numeric to distinguish the "should be" and "maybe cases", and the executor only checks for whether a parameter should be passed by reference and not whether it may be. As a result, the change to pass by reference does not happen for current even though it is a valid candidate. ------------------------------------------------------------------------ [2006-09-14 10:55:22] tony2001@php.net Heh, that's actually interesting. The point is that whether to send a parameter by ref or not is determined in _COMPILE TIME_. Apparently it's not possible to detect it in this case, since the value of $f is not known at that moment. ------------------------------------------------------------------------ [2006-09-13 14:50:06] dev at ioncube dot com Description: ------------ Minor issue; the implementation of "maybe reference" parameters since 5.1.0 (and still present in 5.2RC2) can cause unexpected results. Reproduce code: --------------- <?php $b = array(1=>'one', 2=>'two'); $a =& $b; var_dump(current($a)); next($a); $f = "current"; var_dump($f($a)); ?> Expected result: ---------------- string(3) "one" string(3) "two" Actual result: -------------- string(3) "one" string(3) "one" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38808&edit=1

« previous php.bugs (#102695) next »