php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38808 "maybe ref" issue for current() and others
Submitted: 2006-09-13 14:50 UTC Modified: 2006-09-26 11:26 UTC
From: dev at ioncube dot com Assigned: dmitry (profile)
Status: Closed Package: Variables related
PHP Version: 5.1.6 OS: Any
Private report: No CVE-ID: None
 [2006-09-13 14:50 UTC] 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"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-14 10:55 UTC] 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-14 11:25 UTC] 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-25 13:05 UTC] tony2001@php.net
Dmitry, any ideas?
 [2006-09-26 11:26 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_2.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 10:01:30 2024 UTC