新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
php如何解決項目中多個自動加載沖突?
在有的框架中的自動加載機制,在發(fā)現(xiàn)無法加載時, 直接報錯, 而沒有把控制權轉交給下一個自動加載方法., 如我要引入阿里云日志服務接口sdk,該sdk中自帶自動加載方法,如下:
創(chuàng)新互聯(lián)建站成立與2013年,先為鹽田等服務建站,鹽田等地企業(yè),進行企業(yè)商務咨詢服務。為鹽田企業(yè)網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。
4) $classPath = array_slice($classPath, 0, 4); $filePath = dirname(__FILE__) . '/' . implode('/', $classPath) . '.php'; if (file_exists($filePath)) require_once($filePath); } } spl_autoload_register('Aliyun_Log_PHP_Client_Autoload');
上面自動加載方法會與原有框架自己的加載方法沖突,解決方法如下:
4) $classPath = array_slice($classPath, 0, 4); unset($classPath[0]); $filePath = dirname(__FILE__) . '/' . implode('/', $classPath) . '.php'; if (file_exists($filePath)) require_once($filePath); } } ); // 如果引用本框架的其它框架已經定義了__autoload,要保持其使用 if (function_exists('__autoload')) { spl_autoload_register('__autoload'); } // 再將原來的自動加載函數放回去 if ($oldFunctions){ foreach ($oldFunctions as $f) { spl_autoload_register($f); } } } # 最后調用上面方法 autoloadAdjust();
以上就是php 解決項目中多個自動加載沖突問題的詳細內容,更多請關注創(chuàng)新互聯(lián)其它相關文章!
分享標題:php如何解決項目中多個自動加載沖突?
路徑分享:http://www.dlmjj.cn/article/ghipih.html