On Thu, 2008-11-06 at 10:10 -0800, Stanislav Malyshev wrote: > Hi! > > > So as suggested and wished, here is a patch that add a modifier '%' to > > 'a' in parameter parsing API, where it allows object that implements > > ArrayAccess to be accept. Although it doesn't invoke any their methods, > > i.e. just how it works nowdays. > > I think if you use HASH_OF then any object having get_properties should > be fine... Is there any reason to restrict it to ArrayAccess?
This can be wrong/strange with classes implementing ArrayAccess (not ArrayObject) or Iterator. An example where one might expect an Iterator, reset() and next() use HASH_OF in 5.2: <?php class I implements Iterator { public $foo = "some real property"; public function rewind() { echo __METHOD__, "\n"; } public function current() { echo __METHOD__, "\n"; return "from iterator"; } public function valid() { static $continue = true; echo __METHOD__, "\n"; if ($continue) { $continue = false; return true; } else { return false; } } public function next() {} public function key() {} } $i = new I; reset($i); echo current($i); ?> some real property And another example using ArrayAccess: array_key_exists uses HASH_OF in 5.2: <?php class A implements ArrayAccess { public $foo = 42; function offsetExists($k) { echo __METHOD__; return false; } function offsetGet($k) {} function offsetSet($k, $v) {} function offsetUnset($k) {} } var_dump(array_key_exists("foo", new A())); ?> bool(true) So allowing passing objects to array stuff using HASH_OF can lead to unexpected behavior. Dropping the old behavior makes this clear ... but is bad for stuff like ArrayObject. I'm not sure whether we should add special rules for a single class though .. johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php