Req #49538 [Opn->Wfx]: ArrayAccess Force implement append
Edit report at https://bugs.php.net/bug.php?id=49538&edit=1
ID: 49538
Updated by: levim@php.net
Reported by: kevinpeno at gmail dot com
Summary: ArrayAccess Force implement append
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: SPL related
Operating System: ALL
PHP Version: 5.3.0
Block user comment: N
Private report: N
New Comment:
Thank you for your input. However, the current API allows you to override the
append behavior. It may have been nice to have split these when they were created,
but it has already been finished and it's not going to change.
function offsetSet($k, $v) {
if ($k === NULL) {
$this->append($v);
} else {
parent::offsetSet($k, $v);
}
}
Previous Comments:
------------------------------------------------------------------------
[2009-09-12 22:18:50] kevinpeno at gmail dot com
Dumbass moment on the offsetSet bug. Please ignore that part :P The rest I still would like to see
though :)
------------------------------------------------------------------------
[2009-09-12 22:16:28] kevinpeno at gmail dot com
Description:
------------
ArrayAccess should force the implementation of append to cover the case of $array[] = somevalue so
that one can properly handle values appended in this manner. Additionally, most internal classes
implementing ArrayAccess add their own append method anyway and this would provide some sort of
naming standard.
Examples of conflicts in naming include ArrayObject::append() and SplDoublyLinkedList::push()
Reproduce code:
---------------
<?php
class MyArrayObject extends ArrayObject
{
function append( $v )
{
//Should print the value if value appended
var_dump( 'Append:', $value );
}
function offsetSet( $k, $v )
{
//Will Print OffsetSet: \n NULL \n NULL - See http://bugs.php.net/bug.php?id=49537
var_dump( 'offsetSet:', $k, $value );
}
}
$test = new MyArrayObject();
$test[] = 'test';
?>
Expected result:
----------------
MyArrayObject::append() called rather than MyArrayObject::offsetSet()
Actual result:
--------------
MyArrayObject::offsetSet() is called
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=49538&edit=1
Thread (3 messages)