php判斷類方法是否存在的方法:可以使用method_exists()函數(shù)來(lái)判斷,具體使用方法如:【method_exists($directory,'read')】。method_exists()函數(shù)檢查類的方法是否存在于指定的對(duì)象中。
函數(shù)定義:
(推薦教程:php圖文教程)
method_exists()函數(shù)檢查類的方法是否存在于指定的 object中。如果 method_name 所指的方法在 object 所指的對(duì)象類中已定義,則返回 TRUE,否則返回 FALSE。
函數(shù)語(yǔ)法:
bool method_exists ( mixed $object , string $method_name )
(視頻教程推薦:php視頻教程)
代碼實(shí)現(xiàn):
$directory=new Directory; if(!method_exists($directory,'read')){ echo '未定義read方法!'; }