php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42795 SPL Appendable interface
Submitted: 2007-09-29 07:34 UTC Modified: 2007-09-29 18:37 UTC
From: david dot nqd at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.4 OS: N/A
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: david dot nqd at gmail dot com
New email:
PHP Version: OS:

 

 [2007-09-29 07:34 UTC] david dot nqd at gmail dot com
Description:
------------
SPL interfaces provide useful interfaces to let objects behave like arrays; however, there is no way for objects to use the array append syntax method without having to extend either ArrayObject or ArrayIterator. I am suggesting that a new interface called Appendable be created to allow objects to have this functionality without having to be an extension of anything.

Appendable would only contain a single method, but would almost always be used with ArrayAccess, Appendable differs from the feature request (#32347) I posted earlier since it is not an extension of ArrayAccess.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-29 18:37 UTC] cellog@php.net
This is unnecessary.  the offset is set to null when [] is requested

<?php
class test implements ArrayAccess
{
    var $test = array();
    function offsetGet($var)
    {
        return $this->test[$var];
    }
    function offsetSet($var, $value)
    {
        if ($var === null) {
            $this->test[] = $value;
        }
        $this->test[$var] = $value;
    }
    function offsetExists($var)
    {
        return isset($this->test[$var]);
    }
    function offsetUnset($var)
    {
        unset($this->test[$var]);
    }
}

$a = new test;
$a[] = 1;
echo $a[0];
?>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 03 05:00:01 2025 UTC