It depends on the parameter type.
If your parameter is a primitive type (int, string, float, bool) or an array, value will be used (this will be a local variable into your function), but if you pass a class (stdClass or any other) then it will be a reference, whether you wrote the & or not.
Regards, Pierre.
On Thu, 2009-10-15 at 12:35 +0000, Earnie Boyd wrote:
Quoting andy baxter andy@earthsong.free-online.co.uk:
I have seen it suggested just to remove the & in cases where the function is expecting an object. Does this make sense in PHP terms?
Unless the function is defined incorrectly and doesn't use the purpose of pass by reference then it is absolutely incorrect to remove the & from the parameter. A pass by reference parameter allows changes to the external data. If you remove & then the changes become local to the function and the resultant change is not seen externally.
<?php $a = 1; $b = 2; function c(&$c) { $c = $c * 2; } c($a); c($b); print $a . "\n"; print $b . "\n"; ?>
Result: 2 4
<?php $a = 1; $b = 2; function c($c) { $c = $c * 2; } c($a); c($b); print $a . "\n"; print $b . "\n"; ?>
Result: 1 2
-- Earnie -- http://r-feed.com/ -- http://for-my-kids.com/ -- http://www.4offer.biz/ -- http://give-me-an-offer.com/