ID:               17309
 Comment by:       spagmoid at yahoo dot com
 Reported By:      pmoor at netpeople dot ch
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: linux
 PHP Version:      4.2.1
 New Comment:

This is a good example of why the warning against call-time pass by
reference is a bad idea.  Any function that accepts a reference should
be required to also have the parms use & at call time.  And references
should be allowed as optional parameters ie:

function Blah(&$MayBeBlank=0)


Previous Comments:
------------------------------------------------------------------------

[2002-10-24 16:06:14] [EMAIL PROTECTED]

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.

------------------------------------------------------------------------

[2002-07-05 11:34:57] bram at totalgsm dot 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 at totalgsm dot 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 at totalgsm dot 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 at netpeople dot 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

Reply via email to