|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-12-06 16:32 UTC] vrana@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 13 13:00:01 2025 UTC |
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 ... */