Method_exists
(PHP 4, PHP 5, PHP 7)
method_exists-Check if the method of the class exists
Description
BOOL Method_exists (mixed $object, string $method _name)
Returns TRUE if the method referred to in method_name is defined in the object class referred to by object, otherwise returns FALSE.
The code is as follows |
Copy Code |
Class A { Public Function xx () { echo ' xx '; } Public Function yy () { Echo ' yy '; } } $obj = new A (); Var_dump (method_exists ($obj, ' xx ')); Var_dump (method_exists ($obj, ' xx ')); Var_dump (method_exists ($obj, ' xx ')); The test results are true Class A { Public Function xx () { echo ' xx '; } Public Function yy () { Echo ' yy '; } Public Function yy () { Echo ' yy '; } } $obj = new A (); $obj->yy (); $obj->yy (); |
The above statement is an error.
Example
code is as follows |
copy code |
//Get action to run include ($c _path); //Load Controller file $controller = new $c _name ($query); If (isset ($_get[' m ')) { $method = $_get[' m ']; if ($controller, $method ) { $controller-> $method (); } } else { //performs the first function $controller->index (); } |