Re: Pseudo-objects (methods on arrays, strings, etc.)

From: Date: Tue, 17 Jul 2012 18:47:13 +0000
Subject: Re: Pseudo-objects (methods on arrays, strings, etc.)
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-61373@lists.php.net to get a copy of this message
On 17.07.2012, at 21:50, Stas Malyshev wrote: > Hi! > >> I am for making array a proper class with methods. >> >> "Legacy" functions can be implemented as wrappers around it: >> >> function array_push(&$array, $value) >> { >> $array->push($value); >> } > > The problem there is that array has different semantics than object. Not > completely, but for example if you pass array to function, it is passed > by value and is not modified, but objects are always mutable when passed > to functions. Changing this semantics will break a lot of code. Having special handling of Array objects doesn't sound good too. And I don't see any nice solution. Options are: * "5-to-6" tool, similar to python's "2-to-3" converter, which will fix code. * introduce some kind of per-file declare() option, which would enable pass-by-reference semantics of arrays/strings/etc. in 5.5 which would let people write the same code for 5.5 and 6.x Well, actually, there's one more option: we can introduce "Autocloned" interface (empty, without methods) and force "cloning" of objects, which implement this interface, during parameter-fetching phase. This would allow us to have 2 sets of classes: One set which implements this interface (slower, but backwards-compatible) and another set which doesn't (faster, but not compatible).

Attachment: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc
« previous php.internals (#61373) next »