因此,我有一個(gè)反映我的命名空間結(jié)構(gòu)的目錄。自動(dòng)加載器正在正確加載包含我的課程的文件。use子句使用別名指定正確的類(lèi)。盡管如此,PHP說(shuō)它找不到該類(lèi)。傳統(tǒng)上,我沒(méi)有使用過(guò)名稱(chēng)空間,因?yàn)檫@總是發(fā)生在我身上。但是我試圖強(qiáng)迫自己使用良好的做法。因此,我在這里嘗試了解為什么我無(wú)法使它正常工作。我檢查了自動(dòng)加載器是否實(shí)際上已經(jīng)加載了文件。我檢查了自動(dòng)裝帶器使用的路徑是否正確。我的班級(jí)檔案:<?phpnamespace classes\helpers\core_helper;class core_helper{ public static function create_arg_pairs($arguments) { ..... }}//end core_helper?> 我的主應(yīng)用程序文件:<?phpini_set("display_errors", "1");define('AUTH_ROOT', dirname(__FILE__));use classes\helpers\core_helper as hlpr;function autoloader($class){ if(require_once AUTH_ROOT.'/'.str_replace('\\','/',$class).'.php');}spl_autoload_register('autoloader');......$temp = explode("/", substr($path['path'], 1));//get the controller$contoller = strtolower(array_shift($temp));//get the method$method = strtolower(array_shift($temp));$argArray = hlpr::create_arg_pairs($temp);?> 產(chǎn)生的錯(cuò)誤是:致命錯(cuò)誤:未捕獲的錯(cuò)誤:在/var/www/html/auth/index.php:51中找不到類(lèi)'classes \ helpers \ core_helper':堆棧跟蹤:#0 {main}拋出在/ var / www / html / auth /中第51行的index.php但是我知道包含該類(lèi)的文件已加載,因此正確的名稱(chēng)空間已傳遞到自動(dòng)加載器,并且已正確轉(zhuǎn)換為正確的路徑。那我為什么看不到課程呢?
1 回答

繁花如伊
TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊
通過(guò)說(shuō)
namespace classes\helpers\core_helper;
然后
class core_helper
您是在告訴系統(tǒng)您的實(shí)際班級(jí)是classes\helpers\core_helper\core_helper
。我希望您真正想要的是namespace classes\helpers;
。
- 1 回答
- 0 關(guān)注
- 157 瀏覽
添加回答
舉報(bào)
0/150
提交
取消