Re: Copy On Write and Assign By Reference perform different on PHP5 and PHP7
| From: | Rowan Collins | Date: | Thu, 31 Mar 2016 22:39:07 +0000 |
| Subject: | Re: Copy On Write and Assign By Reference perform different on PHP5 and PHP7 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92055@lists.php.net to get a copy of this message | ||
On 31/03/2016 18:23, Rowan Collins wrote:
Maybe in PHP 5 the opcodes are the same, but $2 and $3 somehow end up as references to !0, rather than new zvalsSo, it turns out, this is exactly what happens. Specifically, there is a call to SEPARATE_ZVAL_IF_NOT_REF(var_ptr); in the definition of the ZEND_PRE_INC opcode [http://lxr.php.net/xref/PHP_5_6/Zend/zend_vm_def.h#814] If the zval *is* a reference, the code just ends up incrementing its reference count, returning a reference to it rather than the calculated value. In PHP 7, references are very different, and integers aren't refcounted, so it's all a different story. I got a bit curious and did some deep investigation, which I've written up on StackOverflow: http://stackoverflow.com/a/36344524/157957 I've about reached my limit now, though, so I'll leave it to others to correct or fill in any further info. :) Regards, -- Rowan Collins [IMSoP]