variable behaviour

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Could you tell me why a zval cannot be both reference AND value ??

This behaviour leads to this amazing thing :

$var2=$var1;   <--  var2 is a "pointer" to var1, sounds normal...

$var3=& $var2 ;

wow... Now $var2 has its own zval memory, It doesn't point anymore to
$var1 !??

I guess, the flag "is_ref" is involved, but I'm not sure...

Anyway, sounds complicated (I mean internally) for a "simple"


Re: variable behaviour

Quoted text here. Click to load it

Well $var2 is an entirely new value, but untill $var1 or $var2 is change=
d,  =

the value isn't copied / doubled as a means of internal PHP optimasation=

Quoted text here. Click to load it

Yes, $var2 is altered in some way. $var3 is a reference to $var2 but NOT=

$var1, alterations on $var1 should not effect $var3. In other words:  =

there's some data in memory available to by $var1. and some data availab=
le  =

to $var2 & $var3. It was probably to difficult (or not worth the trouble=
)  =

to keep track of variable names referencing one another and which ones a=
re  =

'delayed copies, only copied when needed'.

It's an internal PHP thing you shouldn't worry to much about. Possibly i=
t  =

could be optimised to only really duplicate the original value of $var1 =
to  =

$var2 on a change in data, even something references the second one. The=

source is freely available, have fun :)
-- =

Rik Wasmus

Site Timeline