1--TEST-- 2ReflectionClass::getStaticPropertyValue() 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 "Retrieving static values from A:\n"; 21$rcA = new ReflectionClass('A'); 22var_dump($rcA->getStaticPropertyValue("privateOverridden", "default value")); 23var_dump($rcA->getStaticPropertyValue("\0A\0privateOverridden")); 24var_dump($rcA->getStaticPropertyValue("protectedOverridden", "default value")); 25var_dump($rcA->getStaticPropertyValue("\0*\0protectedOverridden")); 26var_dump($rcA->getStaticPropertyValue("publicOverridden")); 27 28echo "\nRetrieving static values from B:\n"; 29$rcB = new ReflectionClass('B'); 30var_dump($rcB->getStaticPropertyValue("\0A\0privateOverridden")); 31var_dump($rcB->getStaticPropertyValue("\0B\0privateOverridden")); 32var_dump($rcB->getStaticPropertyValue("\0*\0protectedOverridden")); 33var_dump($rcB->getStaticPropertyValue("publicOverridden")); 34 35echo "\nRetrieving non-existent values from A with no default value:\n"; 36try { 37 var_dump($rcA->getStaticPropertyValue("protectedOverridden")); 38 echo "you should not see this"; 39} catch (Exception $e) { 40 echo $e->getMessage() . "\n"; 41} 42 43try { 44 var_dump($rcA->getStaticPropertyValue("privateOverridden")); 45 echo "you should not see this"; 46} catch (Exception $e) { 47 echo $e->getMessage() . "\n"; 48} 49 50?> 51--EXPECTF-- 52Retrieving static values from A: 53string(13) "default value" 54 55Fatal error: Uncaught ReflectionException: Class A does not have a property named in %s:%d 56Stack trace: 57#0 %s(%d): ReflectionClass->getStaticPropertyValue('\x00A\x00privateOverr...') 58#1 {main} 59 thrown in %s on line %d 60