title: Are objects in PHP assigned by value or reference?
body: <p>In this code:</p>
  
  <pre><code>&lt;?php
  class Foo
  {
      var $value;
  
      function foo($value)
      {
          $this-&gt;setValue($value);
      }
  
      function setValue($value)
      {
          $this-&gt;value=$value;
      }
  }
  
  class Bar
  {
      var $foos=array();
  
      function Bar()
      {
          for ($x=1; $x&lt;=10; $x++)
          {
              $this-&gt;foos[$x]=new Foo("Foo # $x");
          }
      }
  
      function getFoo($index)
      {
          return $this-&gt;foos[$index];
      }
  
      function test()
      {
          $testFoo=$this-&gt;getFoo(5);
          $testFoo-&gt;setValue("My value has now changed");
      }
  }
  ?&gt;
  </code></pre>
  
  <p>When the method <code>Bar::test()</code> is run and it changes the value of foo # 5 in the array of foo objects, will the actual foo # 5 in the array be affected, or will the <code>$testFoo</code> variable be only a local variable which would cease to exist at the end of the function?</p>