|
Posted by Andy Hassall on 01/01/07 16:40
On 31 Dec 2006 20:04:10 -0800, "howa" <howachen@gmail.com> wrote:
>according to the php manual, it said:
>
>Do not use return-by-reference to increase performance, the engine is
>smart enough to optimize this on its own.
>
>I doubt if this only apply to the PHP5 engine, while if I am using
>PHP4, performance is a factor to continue to use return by refercnece?
This does apply to PHP4. zend.com seem to have rearranged their site which has
made an article on this disappear but it's still available from archive.org:
http://web.archive.org/web/20060427154547/http://www.zend.com/zend/art/ref-count.php
From PHP4, assignments are always done by reference initially, and the work of
doing a copy is only done when the new variable is _modified_. Using references
(excessively) actually ends up doing slightly more work. When you return a
large string value from a function without return-by-reference then it doesn't
start making copies of it - the ref-counting mechanism is supposed to be "smart
enough" to avoid this.
The exception is for objects where you do want (almost) every assignment to be
a reference in PHP4 - but not in PHP5.
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Navigation:
[Reply to this message]
|