|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #49538 ArrayAccess Force implement append
Submitted: 2009-09-12 22:16 UTC Modified: 2012-11-14 21:54 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: kevinpeno at gmail dot com Assigned:
Status: Wont fix Package: SPL related
PHP Version: 5.3.0 OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
30 - 19 = ?
Subscribe to this entry?

 [2009-09-12 22:16 UTC] kevinpeno at gmail dot com
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:
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
		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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-12 22:18 UTC] 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 :)
 [2010-11-24 14:46 UTC]
-Package: Feature/Change Request +Package: SPL related
 [2012-11-14 21:54 UTC]
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) {
    } else {
        parent::offsetSet($k, $v);
 [2012-11-14 21:54 UTC]
-Status: Open +Status: Wont fix
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Dec 05 00:01:26 2023 UTC