Re: Missing __toString() part

From: Date: Sun, 04 Jun 2006 09:47:10 +0000
Subject: Re: Missing __toString() part
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-23911@lists.php.net to get a copy of this message
In case we can't find a solution Andi's (a) approach, I think I like the explicit cast approach better than just implicitly converting to string. Rasmus pointed out that it's not clear why of all types PHP would implicitly convert the object to a string, and chances are that he's not the only person that will be surprised by that behavior. Zeev At 06:20 04/06/2006, Greg Beaver wrote:
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. I prefer to require an explicit (string) cast to use an object as an array index. The "can't use objects as array index" has actually helped me catch many subtle bugs that were slipping through in earlier PHP versions, I very much like this fatal error. I don't see this: $a = $b[$c]; being much clearer to understand than: $a = $b[$c]; or better yet $a = $b[$c->person()]; which is by far the clearest and easiest to debug (and results in a fatal error if $c is the wrong kind of object or the wrong string - even better for debugging) Thanks, Greg


« previous php.internals (#23911) next »