title: php Converting an object implementing ArrayAccess in array
body: <p>When you implement the _toString method on a class, you are able to convert the object in string</p>
  
  <pre><code>$string =(string) $object
  </code></pre>
  
  <p>Is there an equivalent for converting in array</p>
  
  <pre><code>$array=(array) $object
  </code></pre>
  
  <p>From what I have tested, with this code, the attributes of the objet are transformed in index of the array, even if this object implement ArrayAccess.</p>
  
  <p>I expected that casting an object with array access, I would obtain an array thith the same values I could access with the object</p>
  
  <pre><code>public class MyObject implements ArrayAccess{
       private $values;
       public function __construct(array $values){
          $this-&gt;values=$values;
       }
       public function offsetSet($name,$value){
          $this-&gt;values[$name]=$value;
       }
       //etc...
  }
  
  $myObject=new MyObject(array('foo'=&gt;'bar');
  
  $asArray=(array)$myObject;
  
  print_r($asArray);
  // expect array('foo'=&gt;'bar')
  // but get array('MyObjectvalues'=&gt;array('foo'=&gt;'bar'));
  </code></pre>
  
  <p>I also Notice that the native ArrayObject class has a the behavior I expected</p>