On Tue, Dec 12, 2017 at 8:43 AM, Johannes Schlüter <johan...@schlueters.de> wrote:
> > > On December 12, 2017 7:38:54 AM GMT+01:00, Stanislav Malyshev < > smalys...@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. This is no longer the case as of PHP 7. PHP 7 can share values between references and non-references. Nikita