title: Object ->toArray() conversion in php
body: <p>I want to cast a Object to an array, so i can iterate with an loop over it.<br>
  I know that:  </p>
  
  <pre><code>$array = (array) $object 
  </code></pre>
  
  <p>exists. But I want something like the custom </p>
  
  <pre><code>__toString() 
  </code></pre>
  
  <p>method for arrays.<br>
  I know so far that </p>
  
  <pre><code>__toArray()
  </code></pre>
  
  <p>does not exist.<br>
  <strong>Question:</strong><br>
  Can I create this magic method customly and how?<br>
  <em>(I'm also aware of the fact, that i could work around this by just calling a function that returns an array)</em></p>
  
  <p>I want to cast the Object to an custom array:</p>
  
  <pre><code>foreach($object as $key=&gt;$value) {}
  </code></pre>
  
  <p>not converting it by calling a function</p>
  
  <pre><code>foreach($object-&gt;toArray as $key=&gt;$value){}
  </code></pre>
  
  <p>even if it would be the simplest way ... </p>