|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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')
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 18:00:02 2025 UTC |
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')