Re: PHP strategy -- pass complex parameters by value or by reference?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Not sure if you need to worry about it so much. PHP5 does a "copy on
write" (and a default pass by reference) basically. And references are
more like unix symlinks than C pointers. 

http://us3.php.net/manual/en/language.references.php
http://bytes.com/groups/php/769586-copy-write-semantic
http://blog.libssh2.org/index.php?/archives/51-Youre-being-lied-to..html

I suspect your nested functions call overhead is more expensive than
accessing your variables/arrays and you might consider in-lining it
more.
http://www.hudzilla.org/phpbook/read.php/18_1_3

But then again, this seems to contradict this theory a bit in newer PHP
versions:
http://www.webhostingtalk.com/showthread.php?t=538076
http://www.garfieldtech.com/blog/magic-benchmarks
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=php&lang2=php


On Wed, 2009-02-18 at 10:53 +1100, Clancy wrote:

> I have a function to process a data file.  This process opens the file, and then calls
> another function to process each entry.  This function in turn calls another function to
> process each line of the entry.  A set of fairly complex arrays specifies how all the
> possible types of entries and lines should be processed, and each function passes sections
> of these arrays to the next function.
> 
> Is it better to pass the parameters by value, in which case they have to be copied into
> yet more memory when the function is called, or to pass by reference, which I suspect may
> involve additional overhead every time they are accessed?
> 
> And is it better to combine several specifications arrays into one more complex array, and
> pass a single parameter, or to pass them individually as half a dozen different
> parameters?
> 
> I suspect that I am probably asking a "how long is a piece of string?" type of question,
> but are there any general rules which are applicable to this type of situation?
> 



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux