On 24 Sep 2014, at 13:24, Johannes Schlüter <johan...@schlueters.de> wrote:

> Taking this sample code:::
> 
> <?php
> class C {
>    function __toString() {
>        return "C";
>    }
> }
> 
> $a = [];
> 
> $c1 = new C();
> $c2 = new C();
> 
> $a[$c1] = 23;
> $a[$c2] = 42;
> ?>
> 
> 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.

I’m not sure this is a fair example. Don’t classes usually implement a 
`__toString()` that is based on the data they contain? If they don’t, I’m not 
sure they’re useful for indexing anyway.

--
Andrea Faulds
http://ajf.me/





--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to