rfc:hashkey
This is an old revision of the document!
PHP RFC: __toKey magic method
- Version: 0.9
- Date: 2014-10-22
- Author: Joe Watkins
- Status: Draft
- First Published at: http://wiki.php.net/rfc/hashkey
Proposal
A new magic toKey method, to resolve the problem of not being able to use Objects as array keys. The VM will invoke the method on ADD_ARRAY_ELEMENT for keys that have the magic method set.
<?php class Foo { public function __toKey() { return "Foo"; } } $foo = new Foo(); $test = [ $foo => true ];
Inheritance shall work as any other magic method:
<?php class Foo { public function __toKey() { return "Foo"; } } class Bar extends Foo { /* shall use Foo::__toKey unless Bar::__toKey is implemented */ } $bar = new Bar(); $test = [ $bar => true ];
Proposed PHP Version(s)
7
Open Issues
Make sure there are no open issues when the vote starts!
Proposed Voting Choices
The language is changed, so requires a 2/3 majority to pass.
A straight yes/no vote should be conducted.
Patches and Tests
References
Links to external references, discussions or RFCs
Rejected Features
Keep this updated with features that were discussed on the mail lists.
rfc/hashkey.1414000124.txt.gz · Last modified: 2017/09/22 13:28 (external edit)