php判斷方法和屬性是否存在的方法:【method_exists(mixed $object,string $method_name );property_exists(mixed $class,string $property);】。
本文操作環(huán)境:windows10系統(tǒng)、php 7、thinkpad t480電腦。
php判斷類里面的某個方法是否存在:
bool method_exists ( mixed $object , string $method_name ) 檢查類的方法是否存在,例如:
$directory=new Directory; if(!method_exists($directory,'read')){ echo '未定義read方法!'; }
php 判斷類里面的某個屬性是否已經(jīng)定義:
bool property_exists(mixed $class,string $property)檢查類的屬性是否存在,例如:
$directory=new Directory; if(!property_exists($directory,'li')){ echo '未定義li屬性!'; }
推薦學(xué)習(xí):php培訓(xùn)