Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP method_exists not working on class children?

Tags:

php

class parent{
   function run($methodname) {
      echo method_exists(__CLASS__, $methodname);      
   }
}

class child extends parent {
   function order(){
      echo 'hello';
   }
}

$test = new child();
$test->run('order'); //false

The method_exists cannot find the method order in child class.

How to make it work?

like image 494
paragasu Avatar asked Apr 18 '11 08:04

paragasu


1 Answers

__CLASS__ is bound to the class it's used in, not to inheriting classes. You can solve this by using $this as the object reference.

Also see http://www.php.net/manual/en/language.oop5.late-static-bindings.php.

like image 76
deceze Avatar answered Sep 20 '22 14:09

deceze