1--TEST-- 2ReflectionClass::getProperty() 3--CREDITS-- 4Robin Fernandes <robinf@php.net> 5Steve Seear <stevseea@php.net> 6--FILE-- 7<?php 8class pubf { 9 public $a; 10 static public $s; 11} 12class subpubf extends pubf { 13} 14 15class protf { 16 protected $a; 17 static protected $s; 18} 19class subprotf extends protf { 20} 21 22class privf { 23 private $a; 24 static protected $s; 25} 26class subprivf extends privf { 27} 28 29$classes = array("pubf", "subpubf", "protf", "subprotf", 30 "privf", "subprivf"); 31foreach($classes as $class) { 32 echo "Reflecting on class $class: \n"; 33 $rc = new ReflectionClass($class); 34 try { 35 echo " --> Check for s: "; 36 var_dump($rc->getProperty("s")); 37 } catch (exception $e) { 38 echo $e->getMessage() . "\n"; 39 } 40 try { 41 echo " --> Check for a: "; 42 var_dump($rc->getProperty("a")); 43 } catch (exception $e) { 44 echo $e->getMessage() . "\n"; 45 } 46 try { 47 echo " --> Check for A: "; 48 var_dump($rc->getProperty("A")); 49 } catch (exception $e) { 50 echo $e->getMessage() . "\n"; 51 } 52 try { 53 echo " --> Check for doesntExist: "; 54 var_dump($rc->getProperty("doesntExist")); 55 } catch (exception $e) { 56 echo $e->getMessage() . "\n"; 57 } 58 59} 60?> 61--EXPECTF-- 62Reflecting on class pubf: 63 --> Check for s: object(ReflectionProperty)#%d (2) { 64 ["name"]=> 65 string(1) "s" 66 ["class"]=> 67 string(4) "pubf" 68} 69 --> Check for a: object(ReflectionProperty)#%d (2) { 70 ["name"]=> 71 string(1) "a" 72 ["class"]=> 73 string(4) "pubf" 74} 75 --> Check for A: Property A does not exist 76 --> Check for doesntExist: Property doesntExist does not exist 77Reflecting on class subpubf: 78 --> Check for s: object(ReflectionProperty)#%d (2) { 79 ["name"]=> 80 string(1) "s" 81 ["class"]=> 82 string(4) "pubf" 83} 84 --> Check for a: object(ReflectionProperty)#%d (2) { 85 ["name"]=> 86 string(1) "a" 87 ["class"]=> 88 string(4) "pubf" 89} 90 --> Check for A: Property A does not exist 91 --> Check for doesntExist: Property doesntExist does not exist 92Reflecting on class protf: 93 --> Check for s: object(ReflectionProperty)#%d (2) { 94 ["name"]=> 95 string(1) "s" 96 ["class"]=> 97 string(5) "protf" 98} 99 --> Check for a: object(ReflectionProperty)#%d (2) { 100 ["name"]=> 101 string(1) "a" 102 ["class"]=> 103 string(5) "protf" 104} 105 --> Check for A: Property A does not exist 106 --> Check for doesntExist: Property doesntExist does not exist 107Reflecting on class subprotf: 108 --> Check for s: object(ReflectionProperty)#%d (2) { 109 ["name"]=> 110 string(1) "s" 111 ["class"]=> 112 string(5) "protf" 113} 114 --> Check for a: object(ReflectionProperty)#%d (2) { 115 ["name"]=> 116 string(1) "a" 117 ["class"]=> 118 string(5) "protf" 119} 120 --> Check for A: Property A does not exist 121 --> Check for doesntExist: Property doesntExist does not exist 122Reflecting on class privf: 123 --> Check for s: object(ReflectionProperty)#%d (2) { 124 ["name"]=> 125 string(1) "s" 126 ["class"]=> 127 string(5) "privf" 128} 129 --> Check for a: object(ReflectionProperty)#%d (2) { 130 ["name"]=> 131 string(1) "a" 132 ["class"]=> 133 string(5) "privf" 134} 135 --> Check for A: Property A does not exist 136 --> Check for doesntExist: Property doesntExist does not exist 137Reflecting on class subprivf: 138 --> Check for s: object(ReflectionProperty)#%d (2) { 139 ["name"]=> 140 string(1) "s" 141 ["class"]=> 142 string(5) "privf" 143} 144 --> Check for a: Property a does not exist 145 --> Check for A: Property A does not exist 146 --> Check for doesntExist: Property doesntExist does not exist 147