php method to determine whether methods and attributes exist: [method_exists(mixed $object,string $method_name);property_exists(mixed $class,string $property);].
The operating environment of this article: windows10 system, php 7, thinkpad t480 computer.
php determines whether a method in the class exists:
bool method_exists (mixed $object, string $method_name) Check whether the method of the class exists, for example:
$directory=new Directory; if(!method_exists($directory,'read')){ echo '未定义read方法!'; }
PHP determines whether a property in the class has been defined:
bool property_exists(mixed $class, string $property) Check whether the property of the class exists, for example:
$directory=new Directory; if(!property_exists($directory,'li')){ echo '未定义li属性!'; }
Recommended learning: phptraining
The above is the detailed content of How to determine whether methods and attributes exist in php. For more information, please follow other related articles on the PHP Chinese website!