#34445 [Bgs->Opn]: ArrayAccess implementation class cannot be "foreach"-ed
| From: | stochnagara at hotmail dot com | Date: | Fri, 09 Sep 2005 19:14:18 +0000 |
| Subject: | #34445 [Bgs->Opn]: ArrayAccess implementation class cannot be "foreach"-ed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-84811@lists.php.net to get a copy of this message | ||
ID: 34445
User updated by: stochnagara at hotmail dot com
Reported By: stochnagara at hotmail dot com
-Status: Bogus
+Status: Open
Bug Type: Class/Object related
PHP Version: 5CVS-2005-09-09 (snap)
New Comment:
I do not agree with this explanation. I do not perform
foreach ($this as $k => $v) but foreach ($this['options'] as $k => $v)
Also i've tried with $this->params['options'] really set as an array
and it does not work too.
My current workaround is
$opt = $this['options'];
foreach ($opt as $k => $v)
I still consider this is a bug and if there are any technical
difficulties for fixing it, I prefer to see bug status "Won't fix"
rather then "Bogus".
Previous Comments:
------------------------------------------------------------------------
[2005-09-09 20:34:31] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
ArrayAccess is no Iterator
------------------------------------------------------------------------
[2005-09-09 20:30:22] stochnagara at hotmail dot com
Description:
------------
I made a class which implements ArrayAccess. Then I try to use foreach
on one of its array values and I get error "Objects used as arrays in
post/pre increment/decrement must return values by reference"
I've reduced the big code fragment to this small one:
Reproduce code:
---------------
<?
class foo implements ArrayAccess {
protected $params;
public function offsetGet ($field) { return $this->params[$field]; }
public function offsetExists ($field) { return isset
($this->params[$field]); }
public function offsetUnset ($field) { unset ($this->params[$field]);
}
public function offsetSet ($field, $value) { $this->params[$field] =
$value; }
}
$foo = new foo;
foreach ($foo['options'] as $optionvalue => $optiontext) {}
Expected result:
----------------
no errors
Actual result:
--------------
Fatal error: Objects used as arrays in post/pre increment/decrement
must return values by reference in ... on line 161
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34445&edit=1