如果我們要判斷一個(gè)類是不是可以用,可以先使用class_exists函數(shù)來(lái)判斷一下,下面來(lái)看幾個(gè)例子.
bool class_exists ( string $class_name [, bool $autoload = true ] )
此功能是否給定的類被定義檢查,返回true,如果class_name是一個(gè)定義的類,否則返回false.
php實(shí)例代碼如下:
轉(zhuǎn)載請(qǐng)注明來(lái)源:php判斷類是否存在函數(shù) class_exists
- if (class_exists('myclass')) {
- $myclass = new myclass();
- }
- function __autoload($class)
- {
- include($class . '.php');
- // check to see whether the include declared the class
- if (!class_exists($class, false)) {
- trigger_error("unable to load class: $class", e_user_warning);
- }
- }
- if (class_exists('myclass')) {
- $myclass = new myclass();
- }//開源代碼phpfensi.com
哈爾濱品用軟件有限公司致力于為哈爾濱的中小企業(yè)制作大氣、美觀的優(yōu)秀網(wǎng)站,并且能夠搭建符合百度排名規(guī)范的網(wǎng)站基底,使您的網(wǎng)站無(wú)需額外費(fèi)用,即可穩(wěn)步提升排名至首頁(yè)。歡迎體驗(yàn)最佳的哈爾濱網(wǎng)站建設(shè)。
