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.