title: Is there any way to set a private/protected static property using reflection classes?
body: <p>I am trying to perform a backup/restore function for static properties of classes. I can get a list of all of the static properties and their values using the reflection objects <code>getStaticProperties()</code> method. This gets both <code>private</code> and <code>public static</code> properties and their values.</p>
  
  <p>The problem is I do not seem to get the same result when trying to restore the properties with the reflection objects <code>setStaticPropertyValue($key, $value)</code> method. <code>private</code> and <code>protected</code> variables are not visible to this method as they are to <code>getStaticProperties()</code>. Seems inconsistent.</p>
  
  <p>Is there any way to set a private/protected static property using reflection classes, or any other way for that matter?</p>
  
  <p><strong>TRIED</strong></p>
  
  <pre><code>class Foo {
      static public $test1 = 1;
      static protected $test2 = 2;
  
      public function test () {
          echo self::$test1 . '&lt;br&gt;';
          echo self::$test2 . '&lt;br&gt;&lt;br&gt;';
      }
  
      public function change () {
          self::$test1 = 3;
          self::$test2 = 4;
      }
  }
  
  $test = new foo();
  $test-&gt;test();
  
  // Backup
  $test2 = new ReflectionObject($test);
  $backup = $test2-&gt;getStaticProperties();
  
  $test-&gt;change();
  
  // Restore
  foreach ($backup as $key =&gt; $value) {
      $property = $test2-&gt;getProperty($key);
      $property-&gt;setAccessible(true);
      $test2-&gt;setStaticPropertyValue($key, $value);
  }
  
  $test-&gt;test();
  </code></pre>