In the minutes php6 developer meeting, i came across a point where it said that call-time-pass-by-reference is no longer there in PHP6. For example, following both are incorrect for PHP6:
<?php
$foo =& new StdClass();
?>
<?php
function &foo()
{
return new StdClass();
}
$f = foo();
?>
If we can’t use something like this in PHP6:
$foo =& new StdClass();
What is the alternative to that, is there any way to mimic that?
EDIT:
Ans what about variables in PHP6, can we do that for variables eg:
$this->data =& $_SESSION;
You don’t pass parameters by reference, but you still can/must declare your function/method as receiving parameters by reference.
i.e., you don’t do this (passing parameters by reference) :
But you can do this (declaring the function as receiving parameters by reference) :
And… The code examples you gave are not related to call-time-pass-by-reference, but are related to return-by-reference.
For that second thing, what if you just remove the
&? The instance of the object that’s been created inside the function will be returned, and you’ll still be able to work with it, won’t you ?