#42775 [Opn]: BC safe refactorings of ArrayAccess and descendants

From: Date: Thu, 27 Sep 2007 06:29:27 +0000
Subject: #42775 [Opn]: BC safe refactorings of ArrayAccess and descendants
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-117892@lists.php.net to get a copy of this message
ID: 42775 User updated by: david dot nqd at gmail dot com Reported By: david dot nqd at gmail dot com Status: Open Bug Type: Feature/Change Request Operating System: N/A PHP Version: 5.2.4 New Comment: 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') Previous Comments: ------------------------------------------------------------------------ [2007-09-27 06:26:24] 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') ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42775&edit=1

« previous php.bugs (#117892) next »