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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 21:01:33 2024 UTC