#34445 [NEW]: ArrayAccess implementation class cannot be "foreach"-ed
| From: | stochnagara at hotmail dot com | Date: | Fri, 09 Sep 2005 18:30:23 +0000 |
| Subject: | #34445 [NEW]: ArrayAccess implementation class cannot be "foreach"-ed | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-84806@lists.php.net to get a copy of this message | ||
From: stochnagara at hotmail dot com
Operating system:
PHP version: 5CVS-2005-09-09 (snap)
PHP Bug Type: Class/Object related
Bug description: ArrayAccess implementation class cannot be "foreach"-ed
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 bug report at http://bugs.php.net/?id=34445&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34445&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34445&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34445&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=34445&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=34445&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=34445&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=34445&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=34445&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34445&r=support
Expected behavior: http://bugs.php.net/fix.php?id=34445&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=34445&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=34445&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=34445&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34445&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=34445&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=34445&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34445&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=34445&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=34445&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=34445&r=mysqlcfg