On Wed, 2006-07-26 at 22:29, Michael B Allen wrote: > Is a function return value copied? If the value is an integer I suppose > it is but what about a string or an array? If you pass by reference is > the return value still copied? > > For example, is this: > > function foo(&$arr) { > $arr[] = "bar"; > } > > faster than this? > > function foo(&$arr) { > $arr[] = "bar"; > return $arr; // is this copied? > } > > I'm working on some code that would be called to generate a cell in a > possibly large table and therefore a small difference in performance > may have a significant impact. PHP uses copy-on-write and so copies are essentially shared until such time as you modify one of them. If you don't need references then copies are faster than references. 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