design patterns - detect if function exists within the class and if not call a different function. PHP -
i know there other ways around sake of simplicity know if possible like:
myfactory::create()->callme();
and myfactory class:
class myfactory { private $obj; public static create() { $this->obj = new classa(); return $this->obj; } public function __undefinedfunctioncall() { //function not exist within myfactory class exists // in classa $this->obj->callme(); } }
so function callme not exist within myfactory class exists in classa. dont ask me why cant extend classa because code structure written , not me modify it. need way around it.
you use method_exists
it takes 2 parameters method_exists ( mixed $object, string $method_name )
the first object instance or class name, , second method name.
so should simple as:
if(method_exists($this->obj,'callme')){ $this->obj->callme(); } else{ //...throw error logic }
Comments
Post a Comment