<p>I'd like to be able to write a PHP class that behaves like an array and uses normal array syntax for getting &amp; setting.</p>

<p>For example (where Foo is a PHP class of my making):</p>

<pre><code>$foo = new Foo();

$foo['fooKey'] = 'foo value';

echo $foo['fooKey'];
</code></pre>

<p>I know that PHP has the _get and _set magic methods but those don't let you use array notation to access items.  Python handles it by overloading __getitem__ and __setitem__.</p>

<p>Is there a way to do this in PHP?  If it makes a difference, I'm running PHP 5.2.</p>

If you extend
```
ArrayObject
```
or implement
```
ArrayAccess
```
then you can do what you want.
ArrayObject
ArrayAccess