title: PHP 5 passing class Object as parameter, is it always a pointer or a copy or a clone?
body: <p>I have a question about passing object as parameter. When we pass a variable, it creates a copy, but looks like object is always a reference pointer, is this correct? I have tested with the following example code:</p>
  
  <pre><code>class Base 
  {
      private $var;
      function set ($var)
      {
          $this-&gt;var = $var;
      }
  
      function show ()
      {
          echo $this-&gt;var, '&lt;br&gt;';
      }
  }
  
  class Car
  {
      private $obj;
      function __construct($obj)
      {
          $this-&gt;obj = $obj;
      }
  
      function set ($var)
      {
          $this-&gt;obj-&gt;set($var);
      }
  
      function show()
      {
          $this-&gt;obj-&gt;show();
      }
  }
  
  class Bus
  {
      private $obj;
      function __construct($obj)
      {
          $this-&gt;obj = $obj;
      }
  
      function set ($var)
      {
          $this-&gt;obj-&gt;set($var);
      }
  
      function show()
      {
          $this-&gt;obj-&gt;show();
      }
  }
  </code></pre>
  
  <p>And by running</p>
  
  <pre><code>$base = new Base();
  $base-&gt;set('one');
  $base-&gt;show();          // one
  
  $bus = new Bus($base);
  $bus-&gt;show();           // one
  
  $car = new Car($base);
  $car-&gt;set('two');
  $car-&gt;show();           // two
  
  $base-&gt;show();          // two
  
  $bus-&gt;show();           // two
  </code></pre>
  
  <p>The display result is:</p>
  
  <pre><code>one
  one
  two
  two
  two
  </code></pre>
  
  <p>So changing the Base class's variable anywhere even it was passed as parameter into a function or another class will affect all of them, so does this mean it's always pointing to a same object as a pointer?</p>
  
  <p>Thank you.</p>