Re: [PECL-DEV] Re: shared memory extention

[email protected] (Stanislav Malyshev) Thu, 15 Apr 2010 17:35:41 -0700
Newsgroups php.pecl.dev
Organization Zend Technologies
Message-ID <[email protected]>
Hi!

> If that's the case then how are is ref values handled? Everything I read
> says that php does copy on write, so two values can point to the same
> block of data. Can someone please clear this up for me. Thanks

You seem to be confusing variables (the thing you call $foo in the 
language) with zvals (which are internal engine data structures, 
implementing values). Two variables can point to the same zval, simplest 
case:

$a = 1;
$b = $a;

$b and $a share the same zval, which has refcount of 2. Now, if we do:

$b++;

then "copy on write" (which is called "separation" in the engine) 
happens - $b becomes different zval from $a, and both would have 
refcount of 1 now.
If we did:

$b =& $a;

then $a and $b would be reference-bound (still sharing same zval), 
meaning that when we modify either of them, no separation happens, and 
the modification would be reflected in both $a and $b. Note that despite 
the form of the operator, the relationship between $a and $b is entirely 
symmetric, neither of them is different from the other one in any way.
-- 
Stanislav Malyshev, Zend Software Architect
[email protected]   http://www.zend.com/
(408)253-8829   MSN: [email protected]