Req #52308 [Opn->Csd]: ArrayAccess does not automatically $obj[] = $x
| From: | rquadling@php.net | Date: | Mon, 12 Jul 2010 10:36:01 +0000 |
| Subject: | Req #52308 [Opn->Csd]: ArrayAccess does not automatically $obj[] = $x | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-4679@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
Updated by: rquadling@php.net
Reported by: ch@php.net
Summary: ArrayAccess does not automatically $obj[] = $x
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Documentation problem
PHP Version: Irrelevant
-Assigned To:
+Assigned To: rquadling
New Comment:
This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2010-07-11 17:56:43] ch@php.net
var_dump() just showed me that the check should better be:
if ($offset === null)
------------------------------------------------------------------------
[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