To do PHP development, if you encounter their own can not modify the server related configuration can not know whether some of the server functions are open, the direct use of certain special functions can cause programs to error, such as curl_init such a system function. When the server does not open curl related services, direct use of the Curl series functions will be reported to the call to undefined function curl_init () ... Such a mistake.
So what should be done about this? A lot of things are not just a way, if some methods do not, we can also use another method. Here we need to deal with the problem of determining whether a method exists, if it exists, use the method, or use a different method if the method does not exist.
Here is a collation of how to determine whether a function, class, or method exists in a class:
(1) PHP to determine whether the system function or write their own functions exist
BOOL Function_exists (string $function _name) determines whether a function has been defined, for example:
if (function_exists (' Curl_init ')) {
curl_init ();
} else{
echo ' not function Curl_init ';
}
(2) Whether the PHP judge class exists
BOOL Class_exists (String $class _name [, bool $autoload = true]) checks whether a class has been defined, must return true, or FALSE, for example:
if (class_exists (' MySQL ')) {
$myclass =new MySQL ();
}
(3) Whether a method within the PHP judgment class has been defined
the bool Method_exists (mixed $object, string $method _name) checks the existence of the method of the class, for example:
$directory =new directory;
if (!method_exists ($directory, ' read ')) {
echo ' does not define the Read Method! ';
}