|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-03-12 17:38 UTC] fqqdk at freemail dot hu
[2009-12-16 02:29 UTC] tejas dot net+php at gmail dot com
[2010-01-21 19:19 UTC] bytebrite at gmail dot com
[2010-09-23 11:22 UTC] mep_eisen at web dot de
[2011-04-05 19:26 UTC] info at strictcoding dot co dot uk
[2012-06-05 22:24 UTC] nikic@php.net
[2012-06-05 22:24 UTC] nikic@php.net
-Status: Open
+Status: Assigned
-Package: Feature/Change Request
+Package: *General Issues
-Assigned To:
+Assigned To: colder
[2013-02-24 03:04 UTC] stoffle at gmail dot com
[2013-02-24 11:00 UTC] nikic@php.net
[2013-02-24 11:00 UTC] nikic@php.net
-Assigned To: colder
+Assigned To: nikic
[2013-02-24 23:17 UTC] stoffle at gmail dot com
[2013-03-15 07:00 UTC] nikic@php.net
-Status: Assigned
+Status: Closed
[2013-03-15 07:00 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
Description: ------------ A request for foreach to be key-type agnostic (ideally, assoc's would be) so that the following is possible: <?php class Hash implements ArrayAccess, Iterator { private $key = array(); private $val = array(); public function offsetGet($key) { $offset = array_search($key, $this->key); return $this->val[$offset]; } public function offsetSet($key, $val) { $offset = array_search($key, $this->key); if ($offset === false) { $this->key[] = $key; $this->val[] = $val; } else { $this->val[$offset] = $val; } } public function offsetExists($key) { return in_array($key, $this->key); } public function offsetUnset($key) { $offset = array_search($key, $this->key); unset($this->key[$offset], $this->val[$offset]); } public function rewind() { reset($this->key); reset($this->val); } public function key() { return current($this->key); } public function current() { return current($this->val); } public function next() { next($this->key); return next($this->val); } public function valid() { return is_int(key($this->key)); } } $h = new hash; $o0 = new stdclass; $o1 = new stdclass; $o2 = new stdclass; $o3 = new stdclass; foreach (array($o0, $o1, $o2, $o3) as $i => $o) { $o->name = "o" . $i; } $h[$o0] = $o1; $h[$o1] = $o2; $h[$o2] = $o3; foreach ($h as $key => $val) {} ?> Reproduce code: --------------- See description. Expected result: ---------------- foreach ($h as $key => $val) { # $key === $o[012] # $val === $o[123] } Actual result: -------------- foreach ($h as $key => $val) { # Warning: Illegal type returned from Hash::key() # $key === 0 # $val === $o[123] }