- php 判斷類裏面的某個屬性是否已經定義
bool property_exists ( mixed $class , string $property )檢查類的屬性是否存在
$directory=new Directory;
if(!property_exists($directory,'li')){
echo '未定義li屬性!';
}
- php判斷系統函數或自己寫的函數是否存在
bool function_exists ( string $function_name ) 判斷函數是否已經定義
if(function_exists('curl_init')){
curl_init();
}else{
echo 'not function curl_init';
}
- 2.php判斷類是否存在
bool class_exists ( string $class_name [, bool $autoload = true ] ) 檢查一個類是否已經定義,一定以返回true,否則返回false
if(class_exists('MySQL')){
$myclass=new MySQL();
}
- php判斷類裏面的某個方法是否已經定義
bool method_exists ( mixed $object , string $method_name ) 檢查類的方法是否存在
$directory=new Directory;
if(!method_exists($directory,'read')){
echo '未定義read方法!';
}