我試圖做一個loadPlugin(插件)函數,該函數將從插件文件夾中獲取php文件並將其變量/函數加載到該網站中。PHP函數傳遞包含文件
問題是,因爲我們都知道函數不是全局的,這引起了我的問題。
因爲可以包含任何文件,所以我無法將文件中的每個變量都設置爲全局變量,因爲它們可以是隨機的,也可以是無限的,所以我希望使文件中的任何函數都可以在頁面的任何位置使用。
有關如何做到這一點的任何建議將是偉大的。謝謝!
這是我到目前爲止有:
function loadPlugin($name,$debug='') {
if(file_exists("scripts/plugins/".$name)) {
include("scripts/plugins/".$name);
} else if(strtolower($debug)=='d') trigger_error($name." does not exists in the plugins folder.", E_USER_ERROR);
}
感謝您的插件。 :-) –