1--TEST-- 2ReflectionClass::getMethod() 3--CREDITS-- 4Robin Fernandes <robinf@php.net> 5Steve Seear <stevseea@php.net> 6--FILE-- 7<?php 8class pubf { 9 public function f() {} 10 static public function s() {} 11} 12class subpubf extends pubf { 13} 14 15class protf { 16 protected function f() {} 17 static protected function s() {} 18} 19class subprotf extends protf { 20} 21 22class privf { 23 private function f() {} 24 static private function 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 echo " --> Check for f(): "; 35 var_dump($rc->getMethod("f")); 36 echo " --> Check for s(): "; 37 var_dump($rc->getMethod("s")); 38 echo " --> Check for F(): "; 39 var_dump($rc->getMethod("F")); 40 echo " --> Check for doesntExist(): "; 41 try { 42 var_dump($rc->getMethod("doesntExist")); 43 } catch (Exception $e) { 44 echo $e->getMessage() . "\n"; 45 } 46} 47?> 48--EXPECTF-- 49Reflecting on class pubf: 50 --> Check for f(): object(ReflectionMethod)#%d (2) { 51 ["name"]=> 52 string(1) "f" 53 ["class"]=> 54 string(4) "pubf" 55} 56 --> Check for s(): object(ReflectionMethod)#%d (2) { 57 ["name"]=> 58 string(1) "s" 59 ["class"]=> 60 string(4) "pubf" 61} 62 --> Check for F(): object(ReflectionMethod)#%d (2) { 63 ["name"]=> 64 string(1) "f" 65 ["class"]=> 66 string(4) "pubf" 67} 68 --> Check for doesntExist(): Method doesntExist does not exist 69Reflecting on class subpubf: 70 --> Check for f(): object(ReflectionMethod)#%d (2) { 71 ["name"]=> 72 string(1) "f" 73 ["class"]=> 74 string(4) "pubf" 75} 76 --> Check for s(): object(ReflectionMethod)#%d (2) { 77 ["name"]=> 78 string(1) "s" 79 ["class"]=> 80 string(4) "pubf" 81} 82 --> Check for F(): object(ReflectionMethod)#%d (2) { 83 ["name"]=> 84 string(1) "f" 85 ["class"]=> 86 string(4) "pubf" 87} 88 --> Check for doesntExist(): Method doesntExist does not exist 89Reflecting on class protf: 90 --> Check for f(): object(ReflectionMethod)#%d (2) { 91 ["name"]=> 92 string(1) "f" 93 ["class"]=> 94 string(5) "protf" 95} 96 --> Check for s(): object(ReflectionMethod)#%d (2) { 97 ["name"]=> 98 string(1) "s" 99 ["class"]=> 100 string(5) "protf" 101} 102 --> Check for F(): object(ReflectionMethod)#%d (2) { 103 ["name"]=> 104 string(1) "f" 105 ["class"]=> 106 string(5) "protf" 107} 108 --> Check for doesntExist(): Method doesntExist does not exist 109Reflecting on class subprotf: 110 --> Check for f(): object(ReflectionMethod)#%d (2) { 111 ["name"]=> 112 string(1) "f" 113 ["class"]=> 114 string(5) "protf" 115} 116 --> Check for s(): object(ReflectionMethod)#%d (2) { 117 ["name"]=> 118 string(1) "s" 119 ["class"]=> 120 string(5) "protf" 121} 122 --> Check for F(): object(ReflectionMethod)#%d (2) { 123 ["name"]=> 124 string(1) "f" 125 ["class"]=> 126 string(5) "protf" 127} 128 --> Check for doesntExist(): Method doesntExist does not exist 129Reflecting on class privf: 130 --> Check for f(): object(ReflectionMethod)#%d (2) { 131 ["name"]=> 132 string(1) "f" 133 ["class"]=> 134 string(5) "privf" 135} 136 --> Check for s(): object(ReflectionMethod)#%d (2) { 137 ["name"]=> 138 string(1) "s" 139 ["class"]=> 140 string(5) "privf" 141} 142 --> Check for F(): object(ReflectionMethod)#%d (2) { 143 ["name"]=> 144 string(1) "f" 145 ["class"]=> 146 string(5) "privf" 147} 148 --> Check for doesntExist(): Method doesntExist does not exist 149Reflecting on class subprivf: 150 --> Check for f(): object(ReflectionMethod)#%d (2) { 151 ["name"]=> 152 string(1) "f" 153 ["class"]=> 154 string(5) "privf" 155} 156 --> Check for s(): object(ReflectionMethod)#%d (2) { 157 ["name"]=> 158 string(1) "s" 159 ["class"]=> 160 string(5) "privf" 161} 162 --> Check for F(): object(ReflectionMethod)#%d (2) { 163 ["name"]=> 164 string(1) "f" 165 ["class"]=> 166 string(5) "privf" 167} 168 --> Check for doesntExist(): Method doesntExist does not exist 169