[英]PHP autoload debugging with and without composer
花了兩個多小時嘗試調試 PHP 中由拼寫錯誤引起的自動加載問題。
有沒有辦法顯示 PHP 在嘗試加載特定 class 時將查找的文件? 尋找將考慮當前文件的命名空間和任何 spl_autoload / composer 設置的東西。
因此,可以將類似以下內容插入到腳本中以幫助調試:
var_dump(showAutoLoadPaths('myspace\Controller\fancyClass'));
$template = new myspace\fancyClass;
並得到一個 output 像:
array (
0 => 'src/myspace/Controller/fancyClass',
)
Undefined class : fancyClass
允許我運行:
ls -la src/myspace/Controller/fancyClass
ls: cannot access 'Controller': No such file or directory
ls -la src/myspace
drwxrwxr-x 1 user user 74 May 21 15:47 Controllers
從上面可以看出,PHP 正在尋找一個文件夾“Controller”,但該文件夾實際上叫做“Controllers”!
我試圖從 spl_autoload_functions() 解釋 output 但我無法弄清楚文件中的內容。 對現有/內置解決方案的任何建議都會很棒,但如果不存在,任何關於解碼 spl_autoload_functions output 的提示,所以我可以自己寫一些東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.