fork download
  1. <?php
  2.  
  3. class Main {
  4. function a() {}
  5. }
  6.  
  7. class Extended extends Main {
  8. function b() {}
  9. function c() {}
  10. }
  11.  
  12. class ImprovedReflectionMethod extends ReflectionMethod {
  13. private $reflectedClassName;
  14.  
  15. public function __construct($class, $name) {
  16. $this->reflectedClassName = $class;
  17. parent::__construct($class, $name);
  18. }
  19.  
  20. public function isInhereted() {
  21. return $this->class != $this->reflectedClassName;
  22. }
  23. }
  24.  
  25. $className = 'Extended';
  26. $reflectionMethod = new ImprovedReflectionMethod($className, 'a');
  27. echo 'метод ', $reflectionMethod->isInhereted() ? 'унаследован' : 'реализован', PHP_EOL;
  28.  
  29. $reflectionMethod = new ImprovedReflectionMethod($className, 'b');
  30. echo 'метод ', $reflectionMethod->isInhereted() ? 'унаследован' : 'реализован', PHP_EOL;
Success #stdin #stdout 0.02s 23780KB
stdin
Standard input is empty
stdout
метод унаследован
метод реализован