Home > Article > Backend Development > php method_exists detects whether a class includes a function_PHP tutorial
php tutorial method_exists detects whether a class includes a function
The syntax of the method_exists() function is as follows: bool method_exists (object object, string method_name)
The method_exists() function is used to check whether the method of the class exists.
Returns true if the method pointed to by method_name is defined in the object class pointed to by object, otherwise returns false
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 all 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 reports an error.
I just discovered today that the object attributes of PHP are not case-sensitive