Forum Moderators: coopster

Message Too Old, No Replies

Call by ref

         

aspr1n

1:41 pm on May 29, 2003 (gmt 0)

10+ Year Member



If you call a PHP function by ref, an error is generated saying:

Warning: Call-time pass-by-reference has been deprecated - argument passed by value

Yet according to all the documentation I have seen on PHP 5, in future all functions will be called by ref rather than by value, implying it hasn't be deprecated, and is perfectly ok to use.

Anyone know anything on this?

Cheers,

asp

jatar_k

9:50 pm on May 29, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



looks like this setting may help "allow_call_time_pass_reference" in php.ini. What function are you trying to use it with?

aspr1n

10:26 pm on May 29, 2003 (gmt 0)

10+ Year Member



Hi Jatar,

I'm actually trying to call a 3rd party COM object with it. But looking up that setting in php.ini I see:

; Whether to enable the ability to force arguments to be passed by reference
; at function call time. This method is deprecated and is likely to be
; unsupported in future versions of PHP/Zend. The encouraged method of
; specifying which arguments should be passed by reference is in the function
; declaration. You're encouraged to try and turn this option Off and make
; sure your scripts work properly with it in order to ensure they will work
; with future versions of the language (you will receive a warning each time
; you use this feature, and the argument will be passed by value instead of by
; reference).

So thanks for that - at least now I know why!

Cheers,

asp

daisho

4:41 am on May 31, 2003 (gmt 0)

10+ Year Member



You are trying to do this:

<?
function myfunc($id) {
$id="Hello";
}

myfunc(&$myvar);
?>

That is decricated. You should redefine to this:

<?
function myfunc(&$id) {
$id="Hello";
}

myfunc($myvar);
?>

Small but significant difference. The first (your problem) passes variable by reference at runtime. The second (the fix) defines the function saying the variable will be passed by reference (at compile time).

This should solve your problem.

daisho.