rfc:hashkey

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:hashkey [2014/10/22 17:48] krakjoerfc:hashkey [2014/10/22 17:57] krakjoe
Line 7: Line 7:
  
 ===== Proposal ===== ===== 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.+A new magic toKey method, to resolve the problem of not being able to use Objects as array keys.
  
 <code php> <code php>
Line 42: Line 42:
 ]; ];
 </code> </code>
 +
 +Returning a non-scalar shall fail as it did before:
 +
 +<code php>
 +<?php
 +class Foo {
 +    public function __toKey() {
 +        return [];
 +    }
 +}
 +
 +$foo = new Foo();
 +$test = [
 +    $foo => true
 +];
 +</code>
 +
 +Shall yield:
 +
 +<code php>
 +Warning: Illegal offset type in %s on line %d
 +</code>
 +
 +The current behaviour of __toString is unchanged.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
rfc/hashkey.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1