Martin Lucas-Smith wrote:[color=blue]
>
> 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);
>[/color]
There's at least three *major* diffs : the second version
- does not have side-effect, which means you *don't* modify the argument
(and this is a Good Thing(tm)).
- return something, which means you can do thangs like :
$mystr ="here is a string ";
print add_some_extra($mystr)
- can be used with litterals, ie :
print add_some_extra("here is another string");
So the second version is IMHO *much* more clean and useful.
[color=blue]
> other than presumably that the former is less memory-intensive?[/color]
Here you maybe wrong... (see other posts in this thread).
Bruno