Re: Re: Problem with passing function return values by reference
| From: | Andi Gutmans | Date: | Fri, 17 Nov 2000 16:42:19 +0000 |
| Subject: | Re: Re: Problem with passing function return values by reference | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-38434@lists.php.net to get a copy of this message | ||
At 06:34 PM 11/17/00 +0200, Stanislav Malyshev wrote:
CH>> ... then currently you'll get an error (because PEAR::isError() takes a CH>> reference, presumably to avoid copying objects unnecessarily). There are two Actually, AFAIK, it's exactly the reverse - it would always bring unnecessary copied when passing by reference. The reason is simple, let's do: $a = new foo(); $b = $a Here no actual copy happens still. But, if you pass $a or $b by reference, it might be modified, but the other one should remain unchanged, so copies are separated on function call. If it wan't passed by reference, no copy would happen unless function actually modifies the variable. So, using "reference" to avoid copies is totally wrong. Generally, it's bad to try to outsmart the engine - it's smart enough by itself.As a general rule: With objects it's faster to pass by reference. With other data-types it's faster to pass by value. Andi --- Andi Gutmans <andi@zend.com> http://www.zend.com/