Req #52308 [Com]: ArrayAccess does not automatically $obj[] = $x

From: Date: Sun, 11 Jul 2010 15:56:43 +0000
Subject: Req #52308 [Com]: ArrayAccess does not automatically $obj[] = $x
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-4674@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52308&edit=1 ID: 52308 Comment by: ch@php.net Reported by: ch@php.net Summary: ArrayAccess does not automatically $obj[] = $x Status: Open Type: Feature/Change Request Package: Documentation problem PHP Version: Irrelevant New Comment: var_dump() just showed me that the check should better be: if ($offset === null) Previous Comments: ------------------------------------------------------------------------ [2010-07-11 17:50:52] ch@php.net Description: ------------ When implementing the ArrayAccess Interface one could be tempted to think that if "$obj[3] = $x" works, the common syntax "$obj[] = $x" would work as well. But it doesn't. For this to work one has to enhance the offsetSet() method. As it's only a one-liner I propose to put it into the example code on http://de2.php.net/manual/en/class.arrayaccess.php Expected result: ---------------- public function offsetSet($offset, $value) { if ($offset == "") $this->container[] = $value; else $this->container[$offset] = $value; } Actual result: -------------- public function offsetSet($offset, $value) { $this->container[$offset] = $value; } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52308&edit=1

« previous php.doc.bugs (#4674) next »