title: Pass an object as parameter in PHP
body: <p>In Java, I can pass an object straight in parameter </p>
  
  <pre><code>public int foo (Bar bar)
  {
      ... call the methods from Bar class
  }
  </code></pre>
  
  <p>So how can I do same thing with PHP. Thanks
  This is my code:</p>
  
  <pre><code>class Photo
  {
      private $id, $name, $description;
      public function Photo($id, $name, $description)
      {
          $this-&gt;id = $id;
          $this-&gt;name = $name;
          $this-&gt;description = $description;
      }
  }
  class Photos
  {
      private $id = 0;
      private $photos = array();
  
      private function add(Photo $photo)
      {
          array_push($this-&gt;photos, $photo);
      }
      public function addPhoto($name, $description)
      {
          add(new Photo(++$this-&gt;id, $name, $description));
      }
  }
  $photos = new Photos();
  $photos-&gt;addPhoto('a', 'fsdfasd');
  var_dump($photos); // blank
  </code></pre>
  
  <p>If I change the  function add</p>
  
  <pre><code>function add($name, $description)
  {
      array_push($this-&gt;photos, new Photo(++$this-&gt;id, $name, $description));
  }
  </code></pre>
  
  <p>It works pefectly. So What is wrong ?</p>