4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Tests\Fixtures
;
15 * This class is a hand written simplified version of PHP native `ArrayObject`
16 * class, to show that it behaves differently than the PHP native implementation.
18 class CustomArrayObject
implements \ArrayAccess
, \IteratorAggregate
, \Countable
, \Serializable
22 public function __construct(array $array = null)
24 $this->array = $array ?: array();
27 public function offsetExists($offset)
29 return array_key_exists($offset, $this->array);
32 public function offsetGet($offset)
34 return $this->array[$offset];
37 public function offsetSet($offset, $value)
39 if (null === $offset) {
40 $this->array[] = $value;
42 $this->array[$offset] = $value;
46 public function offsetUnset($offset)
48 unset($this->array[$offset]);
51 public function getIterator()
53 return new \
ArrayIterator($this->array);
56 public function count()
58 return count($this->array);
61 public function serialize()
63 return serialize($this->array);
66 public function unserialize($serialized)
68 $this->array = (array) unserialize((string) $serialized);