Reputation: 3209
I have this function in PHP 5:
function myPHPFunction($shows) {
foreach($shows as &$show) {
$showData = $this->Api->getID(null, $show->showId, false);
$show->Id = $showData->Id;
}
return $shows;
}
the $shows array has empty id, I am able to get the id with an Api call and when I return $shows at the end, the id field is populated. If I move this code to PHP 4:
function myPHPFunction($shows) {
foreach($shows as $show) {
$showData = $this->Api->getID(null, $show->showId, false);
$show->Id = $showData->Id;
}
return $shows;
}
The $shows array still has an empty id field when I return is. Does it have something to with &$ because the & does not work in PHP 4
Upvotes: 0
Views: 45
Reputation: 68476
Yes pass by reference was available only after PHP 4.0.4
There is no reference sign on a function call - only on function definitions. Function definitions alone are enough to correctly pass the argument by reference. As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);. And as of PHP 5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal error.
Upvotes: 1