NYCPHP Meetup

NYPHP.org

[nycphp-talk] Copy-on-write

George Webb gw.nyphp at gwprogramming.com
Thu Oct 30 20:27:30 EST 2003


Hi!  This is a followup to Hans's comment about passing variables to
functions (from 'Passing Arrays' thread, Tuesday afternoon).

	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?

	This seems like a really cool trick to try to maximize the
convenience of duplicating a variable's data only when it is actually
necessary to do so.  If no change is actually made to the data,
then there is no need to duplicate it; the function can simply
use the original variable -- because it is only *reading* it.

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

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

	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.


Best, George.

George Webb
gw.nyphp at gwprogramming.com



More information about the talk mailing list