Martin Lucas-Smith wrote:
Having re-read www.php.net/functions.arguments recently, the notion of
passing arguments by reference to a function makes a lot more sense now.
However, my question is: is there any difference in outcome between:
function add_some_extra(&$string) {
$string .= 'and something extra.';
}
add_some_extra($str);
and
function add_some_extra($string) {
$string .= 'and something extra.';
return $string;
}
$str = add_some_extra($str);
Hi,
there is no difference really i would say.
Calling by Reference also doesn't make much
sense here.
But imagine you have an object you would like
to manipulate inside another object.
There you would pass the other object by reference.
For instance if you have an object car and inside you
want to create 4 objects of the type wheel.
Then i would make the wheels and save them
as References.
Otherwise you would lose them
after you leave the car constructor...
ehmmm... jeez... :) that sounds confusing...? :)
Sandy