Alan Knowles wrote:

$x = new Obj;
$y[$x]= 123;

That behaviour is going to be fun to document, and for people unfamilar with it to find in the manual -> php.net/array -> go to array syntax page -> read down to find about objects as keys -> go to __toHash() page...

..whereas...
$x = new Obj;
$y[$x->toHash()]= 123;

they might have a chance to see instantly how that is supposed to work, on the rare occasion that somebody needs this, is it really worth building it into the langauge????

In that case, why not just use the existing __toString explicitly with:

  $x = new Obj;
  $y[(string)$x] = 123;

This works today and basically gives you the same thing. The only thing it doesn't do is separate an array index context from an output context allowing you do different things in the two cases.

I think if we are going to add a toHash thing, it should trigger when the object is used in a hash context, just like toString triggers when it is used in a string context.

-Rasmus

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

Reply via email to