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("privateDoesNotExist", "default value")); 23var_dump($rcA->getStaticPropertyValue("privateOverridden")); 24var_dump($rcA->getStaticPropertyValue("protectedDoesNotExist", "default value")); 25var_dump($rcA->getStaticPropertyValue("protectedOverridden")); 26var_dump($rcA->getStaticPropertyValue("publicOverridden")); 27 28echo "\nRetrieving static values from B:\n"; 29$rcB = new ReflectionClass('B'); 30var_dump($rcB->getStaticPropertyValue("privateOverridden")); 31var_dump($rcB->getStaticPropertyValue("protectedOverridden")); 32var_dump($rcB->getStaticPropertyValue("publicOverridden")); 33 34echo "\nRetrieving non-existent values from A with no default value:\n"; 35try { 36 var_dump($rcA->getStaticPropertyValue("protectedDoesNotExist")); 37 echo "you should not see this"; 38} catch (Exception $e) { 39 echo $e->getMessage() . "\n"; 40} 41 42try { 43 var_dump($rcA->getStaticPropertyValue("privateDoesNotExist")); 44 echo "you should not see this"; 45} catch (Exception $e) { 46 echo $e->getMessage() . "\n"; 47} 48 49?> 50--EXPECT-- 51Retrieving static values from A: 52string(13) "default value" 53string(16) "original private" 54string(13) "default value" 55string(18) "original protected" 56string(15) "original public" 57 58Retrieving static values from B: 59string(15) "changed private" 60string(17) "changed protected" 61string(14) "changed public" 62 63Retrieving non-existent values from A with no default value: 64Class A does not have a property named protectedDoesNotExist 65Class A does not have a property named privateDoesNotExist 66