On 27 October 2014 18:11:48 GMT, Stas Malyshev <smalys...@gmail.com> wrote: >Hi! >> As others noted, it also prevents a full-fledged objects-as-key >> implementation in the future. >You do realize to have such implementation we'd need to rewrite our >hash >layer completely and also introduce the concept of immutable object, >otherwise changing the object would make the hash completely broken? >Which means it would probably never happen unless PHP engine is >radically rewritten.
Regarding the immutability, I was wondering if it would be possible to treat the hash not as a magic method but a magic property, and then enforce immutability by saying that it could only be written once in a given instance. Generally speaking, a value or model object would be able to write to it in the constructor, and any incidental changes to the object (e.g. to lazy load data fields) would not affect it. Potentially, the hash implementation would "only" have to store an object reference next to the existing string (or int) key - all the logic of assigning hash buckets, performing equality checks within buckets, etc, would ignore the object and deal with the scalar value in exactly the same way as if it had been implicitly converted as with the current RFC. If two non-identical objects with the same hash identity were assigned to the same array, there would have to be a decision of which ended up referenced, but as long as it was defined and documented, I can't see either option being a massive problem. I realise that when it came down to brass tacks, it would be more complex than I'm implying - the memory impact of adding a pointer field on every key might be a problem, for instance - but it would be good not to dismiss it as impossible too quickly, and use up the syntax for a less powerful feature. >> In the end it causes issues and brings very little compared to an >> explicit call to convert an object to a key. >Same as __toString obviously is useless as you could just call a method >explicitly. You're putting words into someone else's mouth there. There's a big difference between "brings very little" and "is useless". There are certainly cases where an implicit call would be useful, but they are probably rather rarer than those where the user would want the object back afterwards. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php