php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #35487 allow_call_time_pass_reference - Actually is still possible to pass argument by
Submitted: 2005-11-30 13:40 UTC Modified: 2005-12-06 16:32 UTC
Votes:2
Avg. Score:1.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: kenashkov at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Fedora Core 4
Private report: No CVE-ID: None
 [2005-11-30 13:40 UTC] kenashkov at gmail dot com
Description:
------------
Quote from the docs about the php.ini directive "allow_call_time_pass_reference":
"Whether to enable the ability to force arguments to be passed by reference at function call time. ... "
According to the docs in the second case (=Off) it must warn and _pass by value_. But in both cases (=On =Off) the argument is passed by reference. Wheter the docs are incorrect - it should stand something like:
" Whether to warn when arguments are passed by reference at function call time. ..." 
or it is an internal PHP problem.


In my opinion the call time pass reference is still useful in two cases:

1) serializing recursive arrays:
<?
$arr1[0] =& $arr1;
print_r(unserialize(serialize($arr1)));
?>
expected:
Array
(
    [0] => Array
 *RECURSION*
)
actual:
Array
(
    [0] => Array
        (
            [0] =>
        )

)
This can be solved using:
print_r(unserialize(serialize(&$arr1))) , which is deprecated, or
print_r(unserialize(serialize($ref=&$arr1))), which returns almost as expected:
Array
(
    [0] => Array
        (
            [0] => Array
 *RECURSION*
        )

)
In fact it is the same, although PHP does show the recursion one level deeper.

2) When counting the references to an object. The following code prints the cound of the clones of the object:
<?
class test{}
$obj1 = new test();
$obj2 = $obj1;
debug_zval_dump($obj1);//object(test)(0) refcount(3){ }
?> 
And to count the references to the object we must use:
<?
class test{}
$obj1 = new test();
$ref1 =& $obj1;
debug_zval_dump(&$obj1);//object(test)(0) refcount(3){ }
?> 


Reproduce code:
---------------
<?
/* allow_call_time_pass_reference=Off; */
function test($arg1)
	{
	$arg1 = 55;
	}
$var1 = 44;
test(&$var1);
print $var1;
?>

Expected result:
----------------
44


Actual result:
--------------
55
/* + PHP warning ... */

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-06 16:32 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Whether to warn when arguments are passed by reference at function call time."

"the argument will be passed by value instead of by reference" removed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 02:01:28 2024 UTC