NYCPHP Meetup

NYPHP.org

[nycphp-talk] Copy-on-write

Analysis & Solutions danielc at analysisandsolutions.com
Thu Oct 30 20:52:49 EST 2003


Hey George:

On Thu, Oct 30, 2003 at 08:27:30PM -0500, George Webb wrote:
> 
> 	So is it true that, even though PHP documentation says
> variables passed to functions are, by default, passed-by-value,
> really they are passed by *reference* -- BUT -- only when an actual
> change (i.e. write) is attempted on the variable does a "copy" be
> made?

That's it in essence.  The point of them saying it's passed by value is to
put you on notice that, by default, anything you do to the variable will
only have effect within that function.


> 	Is this really how PHP 4 works?  If so, I'm somewhat impressed!

Yes.


> 	Does anyone know if PHP 5 will do this silent optimization
> as well?

I'm pretty sure this won't change.


> 	As an offshoot topic, is it really good that the documentation
> hides this important performance issue, by simply stating that
> function variables are by default pass-by-value?  I would think that,
> as the prior thread shows, users *do* need to know this.

Perhaps the docs could be clearer, but they're presently geared to my 
point above.  Also, perhaps the docs were written at a point when the 
parameters were actually copied and haven't been changed since?

Enjoy,

--Dan

-- 
     FREE scripts that make web and database programming easier
           http://www.analysisandsolutions.com/software/
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7th Ave #4AJ, Brooklyn NY    v: 718-854-0335   f: 718-854-0409



More information about the talk mailing list