Re: Invokation on __toString() for object used as array key
| From: | Stas Malyshev | Date: | Wed, 24 Sep 2014 19:56:53 +0000 |
| Subject: | Re: Invokation on __toString() for object used as array key | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-77589@lists.php.net to get a copy of this message | ||
Hi!
> There the assumption would be that this leads to an array $a with two
> elements, where in fact there is only one if __toString() is being
> called. The only thing "making sense" would be using using the objects
> identity (i.e. via spl_object_hash()) everything else leads to issues.
This is a valid concern. For this, Java, for example, has separate
methods hashCode() and toString(). Python has __str__, __repr__ and
__hash__. Ruby has object.hash. So maybe we should have another magic,
something like __hash(), that would produce a value for key? Then
objects that implement __hash would be hashable and those that don't
won't be, while still having usable __toString.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/