php - Undefined method error in ReflectionClass but method exists -
i using phpunit unit testing. due presence of protected methods, had use reflection class change visibility of these methods public.
the initial methods called somehow gets stuck @ specific method:
fatal error: call undefined method reflectionclass::create_schema()in /vagrant/fuelphp/fuel/app/tests/model/repository/jobpost.php on line 54 however, dumping method via get_method() var_dump proves exists in class instance:
class reflectionmethod#2317 (2) { public $name => string(13) 'create_schema' public $class => string(34) 'model_repository_feed' } then real confusing bit, decided use hasmethod() see if method exists:
52 echo "if says 1, class exists: ".$this->_target->hasmethod('create_schema'); 53 try { 54 $this->_target->create_schema(); 55 } the result when running says, "yes exists.... doesn't":
if says 1, class exists: 1 fatal error: call undefined method reflectionclass::create_schema() in /vagrant/fuelphp/fuel/app/tests/model/repository/jobpost.php on line 54 to clarify method public , inherited abstract parent class:
public function create_schema() { $this->create_schema_exec(self::$_real_schema_name); } how can issue solved?
you need object of class holds method not reflection object.
$reflection = new reflectionclass($classname); $object = $reflection->newinstancewithoutconstructor(); $object->methodname();
Comments
Post a Comment