Re: Invokation on __toString() for object used as array key
| From: | Andrea Faulds | Date: | Wed, 24 Sep 2014 20:12:55 +0000 |
| Subject: | Re: Invokation on __toString() for object used as array key | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-77593@lists.php.net to get a copy of this message | ||
On 24 Sep 2014, at 21:08, Stas Malyshev <smalyshev@sugarcrm.com> wrote:
> The hash doesn't have to be a nonsensical hex value, it can be something
> like "My Object Number 42" if you want to. The difference is that
> __toString is for human reading, and it's not always suitable for
> hashing purposes. Just read the docs on any of the languages that have
> separate hash method - they all have the same argument, there's a
> different between printing an object for output and using the object as
> a key.
Actually, yeah, I see your point. I suggest this, then:
public function __toKey() : int | string {}
Psuedo-code, since you can’t have multiple return types. I think it’s a better name than __hash
(fits well with __toString IMO), and this way we can support integer keys too, where that makes
sense.
--
Andrea Faulds
http://ajf.me/