rfc:objkey
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:objkey [2014/10/24 05:37] – krakjoe | rfc:objkey [2015/01/07 07:41] – stas | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Objects as hash keys ====== | ====== PHP RFC: Objects as hash keys ====== | ||
- | * Version: | + | * Version: |
- | * Date: 2014-10-21 | + | * Date: 2014-10-26 |
* Author: Stas Malyshev (stas@php.net), | * Author: Stas Malyshev (stas@php.net), | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 26: | Line 26: | ||
method implemented would produce an illegal offset type error when used in hash key position as before. | method implemented would produce an illegal offset type error when used in hash key position as before. | ||
- | ===== Backward Incompatible Changes ===== | + | <code php> |
+ | <?php | ||
+ | class Foo { | ||
+ | public function __hash() { | ||
+ | return " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $foo = new Foo(); | ||
+ | $test = [ | ||
+ | $foo => true | ||
+ | ]; | ||
+ | </ | ||
+ | |||
+ | Inheritance shall work as any other magic method: | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | class Foo { | ||
+ | public function __hash() { | ||
+ | return " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | class Bar extends Foo { | ||
+ | /* shall use Foo::__hash unless Bar::__hash is implemented */ | ||
+ | } | ||
+ | |||
+ | $bar = new Bar(); | ||
+ | $test = [ | ||
+ | $bar => true | ||
+ | ]; | ||
+ | </ | ||
+ | |||
+ | Returning a non-scalar shall fail as it did before: | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | class Foo { | ||
+ | public function __hash() { | ||
+ | return []; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $foo = new Foo(); | ||
+ | $test = [ | ||
+ | $foo => true | ||
+ | ]; | ||
+ | </ | ||
+ | |||
+ | Shall yield: | ||
+ | |||
+ | < | ||
+ | Warning: Illegal offset type in %s on line %d | ||
+ | </ | ||
+ | |||
+ | The current behavior of %%__toString%% is unchanged. | ||
+ | |||
+ | ==== Backward Incompatible Changes ===== | ||
Should not break anything as we don't allow this now. | Should not break anything as we don't allow this now. | ||
Line 46: | Line 104: | ||
Since objects are run-time, should not have any effects on opcache. | Since objects are run-time, should not have any effects on opcache. | ||
- | ==== New Constants ==== | ||
- | |||
- | None. | ||
- | |||
- | ==== php.ini Defaults ==== | ||
- | |||
- | None. | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | Should | + | - Should |
+ | - Should SplObjectStorage support calling %%__hash%% | ||
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
- | New magic method requires 2/3 majority. | + | New magic method requires 2/3 majority. The vote also includes choice for the name - %%__hash%% or %%__toKey%%. Vote for either is counted as the vote for the proposal. |
- | ===== Patches and Tests ===== | + | <doodle title=" |
+ | * Yes, via method __hash | ||
+ | * Yes, via method __toKey | ||
+ | * No | ||
+ | </ | ||
- | http:// | + | The vote runs from December 16, 2014 to the end of day (PDT) January 6, 2015. |
===== Implementation ===== | ===== Implementation ===== | ||
- | TBD | + | https:// |
===== References ===== | ===== References ===== | ||
Line 77: | Line 133: | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
- | Using %%_toString%% for the key conversion, for the reasons discussed above. | + | |
+ | - Supporting the use of objects for string indexes |
rfc/objkey.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1