Andi Gutmans wrote:
Again, I don't think we should have a hash but a unique id which can be
used as an array key and in other things. Difference. Hash implies that
it's not unique, I'm talking about unique. So yes, I'd take the starting
point of Marcus' proposal but:
a) Make the value start with a letter so that this isn't autoconverted
but taken as a literal string key. Again, something like "id=%p:%d"
b) Not call it hash because I see this as a unique id and not as a hash
value which is not unique necessarily.
c) This should be something outside SPL and part of the engine. Question
is again, whether it's explicit or implicit (back to the question I had
earlier). Do you just want to add a function which returns this thing or
do you want $arr[$obj] to automatically ask for it.
These are valid questions and should be answered.
I think if we implement a way to get a hash from an object, or at least
a unique identifier that can be used as a hash, then it should be
implicit just like other things are implicitly converted when the
context is clear. Of course, you should also be able to force it
explicitly. And I don't think there is any point in doing this unless
we also implicitly go the other way. From unique identifier to object.
As in:
class foo { function bar($arg) { echo $arg; } }
$obj1 = new foo;
$obj2 = new foo;
$a = array($obj1=>1,$obj2=>2);
foreach($a as $k=>$v) {
$k->bar($v);
}
Unless this works, I am not sure there is any point to all this. To me
the end goal is to make it possible to use types other than strings and
numbers as array indices which to me also means we should look at doing
the same for arrays.
-Rasmus
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php