On 25/09/14 06:19, Patrick Schaaf wrote: > Am 24.09.2014 22:01 schrieb "Andrea Faulds" <a...@ajf.me>: >> > >> > Now, if we were to add actual object key support, that I might like. But > if we’re going to keep with just integers and strings, I’d much prefer to > just support __toString here. I think users are smart enough to understand > that PHP arrays only have string or int keys, so it casts to a string. > > Once you do that - automatically use __toString on objects used as keys, > the way to full object key support in the future, is completely blocked, > because BC. > > I'd much more like to see full object key support, with spl_object_hash or > a magic __hash() method only used to determine hash slot position > internally.
The problem here is that while OOP has been brought into PHP it's rules have never been fully documented? Using a practical example, if I have an object for say an individual on a family tree data set, there are several elements that can be used as a key or an identifier that the content has changed. The unique ID will need to be used as a key, while a more display friendly 'toString' content including the full name may be more appropriate. We end up with additional functions to create more formalised control of the display functions. Why would we need to build a hash of this object? It would provide nothing of use since we have a clean object key. Some people seem to think a hash will provide an indication that an object has changed, but in reality that is also reliant on what information is imported when the object is loaded. I don't see anything here that can work 'automatically' and be practical? As with much of PHP, this is simply a matter of coding style, and providing a consistent style of object creation THAT IS IDEAL FOR YOUR APPLICATION. Much of the current automatic processes are a compromise and we may get better results by overriding those. Building in more guesses does not seem good practice, but we still do not have particularly good practical demonstrations on how to use much of these advanced features. Currently there is no requirement that __toString will produce a unique ID at all anyway? Adding a new function with that requirement just seems overkill. -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php