fork download
  1. <?php
  2.  
  3. class firstClass {
  4.  
  5. public function firstMethod() {}
  6. private function secondMethod() {}
  7.  
  8. }
  9.  
  10. class secondClass extends firstClass {
  11.  
  12. public function thirdMethod() {}
  13. private function fourthMethod() {}
  14.  
  15. }
  16.  
  17. function check_method($obj, $methodName)
  18. {
  19. $class = new ReflectionClass($obj);
  20. $methods = $class->getMethods();
  21. return [] != array_filter($methods, function($v) use ($methodName, &$obj) {
  22. return $v->name === $methodName && $v->class === get_class($obj);
  23. });
  24. }
  25.  
  26. $obj = new secondClass;
  27. $methodName = 'firstMethod';
  28. var_dump(check_method($obj, $methodName));
Success #stdin #stdout 0.02s 24296KB
stdin
Standard input is empty
stdout
bool(false)