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

From: Date: Tue, 12 Dec 2017 07:43:22 +0000
Subject: Re: [RFC] Explicit call-site send-by-ref syntax
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-101330@lists.php.net to get a copy of this message
On December 12, 2017 7:38:54 AM GMT+01:00, Stanislav Malyshev <smalyshev@gmail.com> wrote: >Hi! > >> I would rather discourage usage of references. Since PHP 7 the cost >of >> breaking cow isn't as expensive anymore, but receiving values by >value >> and returning by value is more idiomatic imo. Using objects can be >more >> efficient. > >Objects are kind of overkill when you just need a modifyable array. And >copying an array when you just need to add one value to a K-size array >is still not a good idea for many apps. O(n) vs O(n^2) still matters. >One should definitely be careful not to overuse refs, but there are >still valid cases for using them. 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. johannes

« previous php.internals (#101330) next »