Returning References

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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?

Re: Returning References

howa wrote:
Quoted text here. Click to load it

Even in PHP 4 you won't find a significant difference (if any) between
return by reference and return by value.

If you're having performance problems, I'd suggest doing some debugging
to figure out where the problems really are.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Returning References

Quoted text here. Click to load it

No, return by reference will not increase performance even in PHP4,
unless you're using a really huge variable with MBs of data, that is
not the common case.

Using references without a technical reason to do that (when you really
need a reference to be returned) wil only cause unecessary annoyances
to the coders.

Remember to mantain your code as simple as possible while this practice
will not cause any perceptible performance or other issues.

Also, its important to say that normally the principal bottleneck in a
common PHP application is the Database, that eventually need a fine
tuning. PHP performance is easily solved using an opcode cache
soluction, like APC, that mantain your scripts compiled in memory,
elimitating the compile time when each access is requested to the

Best regards,

Re: Returning References

Quoted text here. Click to load it

 This does apply to PHP4. seem to have rearranged their site which has
made an article on this disappear but it's still available from

 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 :: :: :: disk and FTP usage analysis tool

Site Timeline