Re: [RFC] Explicit call-site send-by-ref syntax

From: Date: Wed, 13 Dec 2017 05:01:57 +0000
Subject: Re: [RFC] Explicit call-site send-by-ref syntax
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-101346@lists.php.net to get a copy of this message
On Tue, Dec 12, 2017 at 2:43 AM, Johannes Schlüter <johannes@schlueters.de> wrote: > The issue, as you well know, is that references disable copy-on-write. Thus assume you have > code like this: > > function with_ref(&$a) { > count ($a); > } > > function no_ref($a) { > count($a); > } > > The count in with_ref() will copy the array, while no_ref() can use copy on write and > won't actually copy. > That *was* true in PHP 5. In PHP 7, the with_ref() version has a very slight overhead boxing the array into an IS_REF zval, then unboxing it for the call to count(). This isn't a deep (or even shallow) copy. It's one extra zval alloc and a few integer ops. -Sara

« previous php.internals (#101346) next »