우리의 자동 로더 신비한 문제가 있습니다 (리눅스에서 작동) :require_once를이
function psr4_default_autoload($class)
{
// project-specific namespace prefix
$prefix = 'basefolder\\';
// base directory for the namespace prefix
$base_dir = SOURCE_DIR . '/';
// does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}
// get the relative class name
$relative_class = substr($class, $len);
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require_once $file;
}
}
SOURCE_DIR
절대 경로입니다. 그렇지 않으면 원래 psr4 오토로더 예제입니다. https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
이 오토로더는 Linux PC와 서버에서 작동합니다. 그러나 Windows file_exists($file)
에서 true를 반환하지만 require_once $file;
은 작동하지 않습니다. $file
을 되풀이하면 정확하게로드 할 파일을 반환하고 파일도 정확하게로드합니다.
오류 메시지는 다음과 같습니다
Fatal error: Class 'basedir\DatabaseAbstraction\AEntity' not found in C:\xampp\htdocs\xyz\classes\DatabaseAbstraction\Entity\UserLogin.php on line 14
그 라인은 다음과 같습니다 class UserLogin extends AEntity
. 상황 :
namespace basedir\DatabaseAbstraction\Entity;
use basedir\DatabaseAbstraction\AEntity;
class UserLogin extends AEntity
아이디어가 있습니까?
어쨌든 나는 당신이 문제를 직면했기 때문에 내 대답을 계속하겠다. 내가 생각하기에 ... 편집에 관해서는, 오류가 발생했을 때'$ file'의 내용은 무엇인가? – NaeiKinDus
'$ file'로 모든 것이 잘됩니다. ' php'에 PHP가 없습니다 ... – Tekay37
적어도 지금 뭔가 작동하고 있습니다. 비록 이것에 대한 수표를 추가하는 것이 좋을 수도 있습니다;) – NaeiKinDus