Home  >  Article  >  Backend Development  >  php method_exists detects whether a class includes a function_PHP tutorial

php method_exists detects whether a class includes a function_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:02:351484browse

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


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445353.htmlTechArticlephp tutorial method_exists Detect whether the function method_exists() is included in the class. The syntax of the function is as follows: bool method_exists (object object, string method_name) method_exists() function...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn