#17309 [Opn->Bgs]: pass by reference in call_user_func
| From: | iliaa@php.net | Date: | Thu, 24 Oct 2002 21:06:14 +0000 |
| Subject: | #17309 [Opn->Bgs]: pass by reference in call_user_func | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-23245@lists.php.net to get a copy of this message | ||
ID: 17309
Updated by: iliaa@php.net
Reported By: pmoor@netpeople.ch
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: linux
PHP Version: 4.2.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
When you do ' call_user_func("pass_by_reference", $data ); ' you
actually pass the $data variable to the call_user_func first and that
function will internally pass $data to the function specified in the
first argument. Unless $data is passed to call_user_func by reference,
the call_user_func simply makes a copy of the $data variable and passes
that copy to the pass_by_reference function. Hence the 'invalid'
output, which you see.
If you do ' pass_by_reference( $data ); ' it works, because the
function has been defined to accept the parameter by reference.
Previous Comments:
------------------------------------------------------------------------
[2002-07-05 11:34:57] bram@totalgsm.net
This might be a duplicate of:
http://bugs.php.net/bug.php?id=17246
However, this test case is clearer.
------------------------------------------------------------------------
[2002-07-05 11:34:10] bram@totalgsm.net
This might be a duplicate of:
http://bugs.php.net/bug.php?id=17246
However, this test case is clearer.
------------------------------------------------------------------------
[2002-07-05 11:32:05] bram@totalgsm.net
A workaround might be using variable function name like
$func_name = 'pass_by_reference';
$funcname($data);
However this doesn't work if the $func_name is an array to call a user
method (which is a flaw in PHP :( )
------------------------------------------------------------------------
[2002-05-20 11:01:03] pmoor@netpeople.ch
i've disabled the "call-time pass-by-reference" option in my
configuration file.
now, when trying to call_user_func a function with
reference-parameters, it won't work, unless i
call-time-pass-by-reference my parameters despite the warning.
( this bug might be related to bug #17246 )
here a small example:
function pass_by_reference( &$param ) {
$param[] = "another entry";
}
$data = array( "a first entry" );
call_user_func( "pass_by_reference", $data );
var_dump($data); // $data contains only one element ( "a first entry" )
( == unexpected behaviour )
$data = array( "a first entry" );
call_user_func( "pass_by_reference", &$data ); // Warning: Call-time
pass-by-reference has been deprecated - argument passed by value; ...
var_dump($data); // $data contains both elements ( "a first entry",
"another entry" ) ( == expected behaviour )
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=17309&edit=1