1--TEST-- 2ReflectionClass::setStaticPropertyValue() 3--CREDITS-- 4Robin Fernandes <robinf@php.net> 5Steve Seear <stevseea@php.net> 6--FILE-- 7<?php 8class A { 9 static private $privateOverridden = "original private"; 10 static protected $protectedOverridden = "original protected"; 11 static public $publicOverridden = "original public"; 12} 13 14class B extends A { 15 static private $privateOverridden = "changed private"; 16 static protected $protectedOverridden = "changed protected"; 17 static public $publicOverridden = "changed public"; 18} 19 20echo "Set static values in A:\n"; 21$rcA = new ReflectionClass('A'); 22$rcA->setStaticPropertyValue("\0A\0privateOverridden", "new value 1"); 23$rcA->setStaticPropertyValue("\0*\0protectedOverridden", "new value 2"); 24$rcA->setStaticPropertyValue("publicOverridden", "new value 3"); 25print_r($rcA->getStaticProperties()); 26 27echo "\nSet static values in B:\n"; 28$rcB = new ReflectionClass('B'); 29$rcB->setStaticPropertyValue("\0A\0privateOverridden", "new value 4"); 30$rcB->setStaticPropertyValue("\0B\0privateOverridden", "new value 5"); 31$rcB->setStaticPropertyValue("\0*\0protectedOverridden", "new value 6"); 32$rcB->setStaticPropertyValue("publicOverridden", "new value 7"); 33print_r($rcA->getStaticProperties()); 34print_r($rcB->getStaticProperties()); 35 36echo "\nSet non-existent values from A with no default value:\n"; 37try { 38 var_dump($rcA->setStaticPropertyValue("protectedOverridden", "new value 8")); 39 echo "you should not see this"; 40} catch (Exception $e) { 41 echo $e->getMessage() . "\n"; 42} 43 44try { 45 var_dump($rcA->setStaticPropertyValue("privateOverridden", "new value 9")); 46 echo "you should not see this"; 47} catch (Exception $e) { 48 echo $e->getMessage() . "\n"; 49} 50 51?> 52--EXPECTF-- 53Set static values in A: 54 55Fatal error: Uncaught ReflectionException: Class A does not have a property named in %s:%d 56Stack trace: 57#0 %s(%d): ReflectionClass->setStaticPropertyValue('\x00A\x00privateOverr...', 'new value 1') 58#1 {main} 59 thrown in %s on line %d 60