Page 1 of 1
Warning Message From fsockopen()
Posted: Sat Dec 12, 2009 9:24 pm
by JackD
The following code generates two identical warning messages when it executes the fsockopen(). Is there a way to suppress or eliminate these messages? I tried adding a timeout value to the call, but it did not help.
Code: Select all
$SockErr = 0;
$SockErrMsg = "";
if (!$Socket_Fd = fsockopen('96.38.238.50', '8000', &$SockErr, &$SockErrMsg))
{ echo $SockErr . ' - ' . $SockErrMsg;
exit;
}
The warning message is:
Warning: Call-time pass-by-reference has been deprecated in /home/content/13/5169913/html/ordering.php on line 5
Re: Warning Message From fsockopen()
Posted: Sat Dec 12, 2009 9:56 pm
by Weirdan
JackD wrote:Is there a way to suppress or eliminate these messages?
Sure. It is using & in a function
call that is deprecated. Remove those ampersands and warning will go away.
Re: Warning Message From fsockopen()
Posted: Sat Dec 12, 2009 10:09 pm
by JackD
Thanks! I thought I had to use those as pointer designations so the error info could be posted to them. The php manual gave the following:
resource fsockopen ( string $hostname [, int $port = -1 [, int &$errno [, string &$errstr [, float $timeout = ini_get("default_socket_timeout") ]]]] )
What is the purpose of the '&' in the above reference?
Re: Warning Message From fsockopen()
Posted: Thu Dec 17, 2009 9:59 am
by Weirdan
JackD wrote:The php manual gave the following:
resource fsockopen ( string $hostname [, int $port = -1 [, int &$errno [, string &$errstr [, float $timeout = ini_get("default_socket_timeout") ]]]] )
What is the purpose of the '&' in the above reference?
It says that function is free to modify its parameter - and those modifications will be visible to function caller. Consider this example:
Code: Select all
function byRef(&$a) {
$a = 1;
}
function byVal($a) {
$a = 1;
}
$a = 10;
byRef($a);
var_dump($a); // 1
$a = 10;
byVal($a);
var_dump($a); // 10
Function signatures that are shown in the PHP manual are how php programmer would have written their declaration (with some additional pseudo-syntax to signify argument types). So, signature for byRef I would write down like:
, and signature for byVal like this:
Previously it was possible to force parameter to be passed by reference even to those function that did not declare the parameter as accepted by reference. So in old versions of php if I called
I would get $a modified. Now this option is no longer supported (and for good reasons) and instead you get the warning.
Re: Warning Message From fsockopen()
Posted: Thu Dec 17, 2009 11:18 am
by JackD
So, without the '&', the argument is passed as a constant that cannot be changed by the function, while with the '&' the argument is passed as a variable that can assigned a new value by the function that is visible to the caller.
Thank you very much!!
Re: Warning Message From fsockopen()
Posted: Thu Dec 17, 2009 11:38 am
by Weirdan
JackD wrote:So, without the '&', the argument is passed as a constant that cannot be changed by the function, while with the '&' the argument is passed as a variable that can assigned a new value by the function that is visible to the caller.
Without the '&' in function
declaration the argument is passed as 'cheap copy' - meaning if you attempt to change it from inside the function php interpreter will create a copy of it and perform modification on the copy. Overall it results in that you
can change the argument value, but this change won't be visible outside the function. Using '&' in function
call has no effect other than producing a warning (unless you have allow_call_time_pass_reference enabled in php.ini).