1--TEST-- 2ReflectionClass::hasMethod() 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->hasMethod("f")); 36 echo " --> Check for s(): "; 37 var_dump($rc->hasMethod("s")); 38 echo " --> Check for F(): "; 39 var_dump($rc->hasMethod("F")); 40 echo " --> Check for doesntExist(): "; 41 var_dump($rc->hasMethod("doesntExist")); 42} 43?> 44--EXPECTF-- 45Reflecting on class pubf: 46 --> Check for f(): bool(true) 47 --> Check for s(): bool(true) 48 --> Check for F(): bool(true) 49 --> Check for doesntExist(): bool(false) 50Reflecting on class subpubf: 51 --> Check for f(): bool(true) 52 --> Check for s(): bool(true) 53 --> Check for F(): bool(true) 54 --> Check for doesntExist(): bool(false) 55Reflecting on class protf: 56 --> Check for f(): bool(true) 57 --> Check for s(): bool(true) 58 --> Check for F(): bool(true) 59 --> Check for doesntExist(): bool(false) 60Reflecting on class subprotf: 61 --> Check for f(): bool(true) 62 --> Check for s(): bool(true) 63 --> Check for F(): bool(true) 64 --> Check for doesntExist(): bool(false) 65Reflecting on class privf: 66 --> Check for f(): bool(true) 67 --> Check for s(): bool(true) 68 --> Check for F(): bool(true) 69 --> Check for doesntExist(): bool(false) 70Reflecting on class subprivf: 71 --> Check for f(): bool(true) 72 --> Check for s(): bool(true) 73 --> Check for F(): bool(true) 74 --> Check for doesntExist(): bool(false) 75