title: How can I use PHP reflection to set a static property?
body: <p>I am using PHPUnit to make a mock class for testing.</p>
  
  <pre><code>class Item extends Object {
    protected static $_cache;
  }
  </code></pre>
  
  <p>I am pretty certain mocking does something like this ( please correct me if I'm wrong ):</p>
  
  <pre><code>class Mock_Item_randomstring extends Item {
  
  }
  </code></pre>
  
  <p>When my <code>Item</code>'s cache gets populated, it's checking to see that the object being passed in is an instance of <code>Item</code>. Since the mock is not explicitly defining <code>$_cache</code>, it fails the check for instance type.</p>
  
  <p>PHP doesn't really document the reflection functions well at all. Is there a way to set the static variable after the fact so the class would become</p>
  
  <pre><code>class Mock_Item_randomstring extends Item {
    protected static $_cache;
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I played around with reflection methods and ran into a variety of issues. Here is one that I'm confused about:</p>
  
  <pre><code>$mock = $this-&gt;getMock( 'Item', array( '_func' ), array(
    $argument1, $argument2
  ));
  
  $mock = new ReflectionClass($mock); 
  
  
  $mock-&gt;staticExpects( $this-&gt;exactly(2) )-&gt;method( '_func' );
  </code></pre>
  
  <p>I was under the assumption reflections copy the entire class. I get this error:
  <code>Call to undefined method ReflectionClass::staticExpects()</code> </p>