On Tue, Dec 12, 2017 at 2:43 AM, Johannes Schlüter <johan...@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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php