On Wed, 2004-03-10 at 02:07, Kelly Hallman wrote: > Consider this method: > > function xyz() { > return $this->data = unserialize($this->serial); } > > A few assumptions: > - Resultant data large enough to warrant discussion of efficiency > - I always want to store the unserialized data into the object > - The return value is only needed sometimes > > If I only need to grab the return value on occassion, what is the > overhead of returning the value, if it's discarded most of the time? > > Example: > $obj->xyz(); // method returns data, but nothing is done with it > > Same difference? > Or better to break this out and only use return when needed? > > Appreciate any expert responses. I don't know enough about the internals > of PHP to know the implications of this... thank you!
Overhead is minimal since PHP doesn't actually copy the contents of the container until an attempt to modify it is made. At which time the contents are only actually copied if the internal reference count is greater than 0. Generally this means it won't be copied since your returning function will no longer be referencing it. This is not to be confused with references as programmers work with them in scripts themselves. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php