title: Which PHP interface allows objects' properties to be accessible with array notation?
body: <p>Which PHP SPL interface allows objects to do this:</p>
  
  <pre><code>$object-&gt;month = 'january';
  echo $object['month']; // january
  
  $record['day'] = 'saturday';
  echo $record-&gt;day; // saturday
  </code></pre>
  
  <p>e.g. such as in libraries like Doctrine (Doctrine_Record)</p>
  
  <p>how do I implement this? I've tried using ArrayObject, but they don't behave as I thought they would.</p>
  
  <p>i.e.</p>
  
  <pre><code>$object = new ArrayObject();
  $object['a'] = 'test';
  $object['a'] == $object-&gt;a; // false
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I tried a barebone implementation that I called Arrayable.</p>
  
  <pre><code>class Arrayable implements ArrayAccess
  {
      protected $container = array();
  
      # implement ArrayAccess methods to allow array notation 
      # $object = new Arrayable();
      # $object['value'] = 'some data';
  
      function offsetExists($offset)
      {
          return isset($this-&gt;container[$offset]);
      }
  
      function offsetGet($offset)
      {
          return $this-&gt;container[$offset];
      }
  
      function offsetSet($offset, $value)
      {
          $this-&gt;container[$offset] = $value;
      }
  
      function offsetUnset($offset)
      {
          unset($this-&gt;container[$offset]);
      }
  
      # now, force $object-&gt;value to map to $object['value'] 
      # using magic methods
  
      function __set($offset, $value)
      {
          $this-&gt;offsetSet($offset, $value);
      }
  
      function __get($offset)
      {
          return $this-&gt;offsetGet($offset); 
      }
  }
  </code></pre>