php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42775 BC safe refactorings of ArrayAccess and descendants
Submitted: 2007-09-27 06:26 UTC Modified: 2007-09-29 18:36 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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: david dot nqd at gmail dot com
New email:
PHP Version: OS:

 

 [2007-09-27 06:26 UTC] david dot nqd at gmail dot com
Description:
------------
A new interface called 'AppendableArrayAccess' that extends ArrayAccess (and be implemented by ArrayIterator and ArrayObject). This new interface is simply a push up of the append() method from ArrayIterator and ArrayObject.

Reproduce code:
---------------
<?php
class Example implements AppendableArrayAccess {
    public $array;

    public function __construct () {
        $this->array = array();
    }

    public function offsetGet($offset) {
        return $this->array[$offset];
    }

    public function offsetSet($offset, $value) {
        $this->array[$offset] = $value;
    }

    public function offsetExists($offset) {
        return isset($this->array[$offset]);
    }

    public function offsetUnset($offset) {
        unset($this->array[$offset]);
    }
}

$x = new Example();
$x[] = "abc";
$x[] = "def";
var_dump($x->array);
?>

Expected result:
----------------
// Using ArrayAccess as opposed to AppendableArrayAccess
// which doesn't currently exist
the array: array('def')

Actual result:
--------------
the array: array('abc', 'def')

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-27 06:29 UTC] david dot nqd at gmail dot com
I've made a mistake on the actual/expected results. It should be:
Expected result:
----------------
the array: array('abc', 'def')

Actual result:
--------------
// Using ArrayAccess as opposed to AppendableArrayAccess
// which doesn't currently exist
the array: array('' => 'def')
 [2007-09-29 07:03 UTC] david dot nqd at gmail dot com
closed
 [2007-09-29 18:36 UTC] cellog@php.net
closed is for implemented features
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 13:01:36 2025 UTC