php.net |  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
Votes:1
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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kevinpeno at gmail dot com
New email:
PHP Version: OS:

 

 [2009-09-12 22:16 UTC] 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

Patches

Pull Requests

History

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] jani@php.net
-Package: Feature/Change Request +Package: SPL related
 [2012-11-14 21:54 UTC] levim@php.net
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);
    }
}
 [2012-11-14 21:54 UTC] levim@php.net
-Status: Open +Status: Wont fix
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC