title: Implementing a .Net Collection like class in PHP
body: <p>So, i would like to implement something like this:</p>
  
  <pre><code>class Collection{
     private $array;
     public function add($object){
        array_push($this-&gt;array, $object);
     }
     public function array(){
        return $this-&gt;array;
     }
  }
  class JustaClass{
     public $myCollection;
     public function __construct(){
        $this-&gt;myCollection = new Collection();
     }
  }
  
  $justAnObject = new JustaClass();
  $justAnObject-&gt;myCollection-&gt;add(new SomeObject());
  </code></pre>
  
  <p>this works just fine, but i would like to work with it  like i do in .Net, ie, when i want to refer to the collection Object, i would like to do it directly, like:</p>
  
  <pre><code>foreach($justAnObject-&gt;myCollection as $collectionItem)
  </code></pre>
  
  <p>and not like</p>
  
  <pre><code>foreach($justAnObject-&gt;myCollection-&gt;array() as $collectionItem)
  </code></pre>
  
  <p>Is there any way I can do this? maybe a magic method, or implementing an Iiterator-like interface?</p>
  
  <p>thanks</p>