|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34445 ArrayAccess implementation class cannot be "foreach"-ed
Submitted: 2005-09-09 20:30 UTC Modified: 2005-09-10 23:23 UTC
Avg. Score:4.0 ± 0.9
Reproduced:7 of 7 (100.0%)
Same Version:2 (28.6%)
Same OS:4 (57.1%)
From: stochnagara at hotmail dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 5CVS-2005-09-09 (snap) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: stochnagara at hotmail dot com
New email:
PHP Version: OS:


 [2005-09-09 20:30 UTC] stochnagara at hotmail dot com
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-09 20:34 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

ArrayAccess is no Iterator 
 [2005-09-09 21:14 UTC] stochnagara at hotmail dot com
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".
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Jan 27 00:05:52 2023 UTC