Jump to content

Call-time pass-by-reference? Deprecated Ampersand Question.


fubowl

Recommended Posts

Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of fsockopen(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in ...

 

I came across this in a script I just purchased. This is the second time in a week I've come across it. I know this error is caused by using

&$somevar

, and my question is what did this used to do? When I search for it I only come up with answers on how to allow Call-time pass-by-reference in the ini as a language option. But still, what the hell is the ampersand supposed to do!??!

 

Thanks.

Link to comment
Share on other sites

Try the following:

 

$a = 1;
foo(&$a);
print "a = $a\n";
bar($a);
print "a = $a\n";

function foo(&$a) {
  $a = $a + 1;
}
function foo($a) {
  $a = $a + 1;
}

 

When $a is passed by reference and modified inside the function, the original copy is modified too.  They are the same variable.  But if it is passed by value (the default behaviour) then only the copy inside the function is modified.

 

You should probably ask the script's vendor for advice on what to do.

Link to comment
Share on other sites

you appear to have a script built for php4 running on a php5 box (I love 5!)

 

passing by reference means you actually pass the entity itself (any manipulation done in the function would affect the entity and not a COPY of the entity). fsockopen has absolutley no requirement to recieve anything by reference so where ever you see & used inside fsockopen just delete the &!

Link to comment
Share on other sites

referencing isn't built for php4, it just has slightly different rules between php4 and 5.

 

There was a typo in my example.  After fixing that, it works the same in both 4 and 5.

 

$a = 1;
foo(&$a);
print "a = $a\n";
bar($a);
print "a = $a\n";

function foo(&$a) {
  $a = $a + 1;
}
function bar($a) {
  $a = $a + 1;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.