0
所以這裏是我的代碼。它在我使用較長的陳述時有效,但當我使用速記時不起作用。對不起,我的英語不好。速記If/Else require_once PHP
<?php
function __autoload($class) {
$path = "includes/{$class}.php";
// IT WORKS LIKE THIS
if (file_exists($path)) {
require_once($path);
}
else {
die("File Not Found :(");
}
//But Not Like This
require_once() file_exists($path) ? $path : die("File Not Found :(");
}
?>
你不工作的替代方法有效的語法,只是不會工作require_once()file_exists($路徑)。我強烈建議你只使用作曲家自動加載器,如果你使用任何第三方代碼,你會無論如何使用它。 – JimL
這是一個語法錯誤,這就是爲什麼它不起作用。 – Nehal