On Sat, Jun 03, 2006 at 01:42:12PM +0200, Marcus Boerger wrote: > Hello guys, > > the attached patch closes one more __toString() part. It allows > to use objects that define __toString as indexes to arrays. What do > you guys think about this, should we add it or stay with the old > behavior that didn't allow objects as indexes at all.
Like others who have contributed to the thread I agree that it would be useful, but I think using __toString() wrong for this. There is a confusion two ideas here: 1. The string representation of an object, probably human readable, lucent string. 2. A unique hash of an object use to identify it programmatically, and likely unique. Probably a non-human friendly, opaque value. These are not the same thing. The latter is what, IMO, would be used for an objects value as an index into an array, not the former. The latter is available ... currently I do this like so: class a{ public function __toString() { return 'an object';}} $foo = new a; $bar = new a; $arr = new array() $arr[(string)$foo] = $foo; // The index is "Object id #1" $arr[(string)$bar] = $bar; // The index is "Object id #2" Note that the __tostring method is not used in the cast - a spearate issue, but needs to be pointed out for this issue. Therefore my suggested alternative to Marcus' patch is: When Objects are used in array index context, use the object ID or some variation. And, possibly, provide a magic method, or interface to generate an hash value of an object. Regards, Andrew -- Andrew Yochum Plexpod [EMAIL PROTECTED] 718-360-0879 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php