无法找到 class,即使自动加载器已加载文件

Unable to find class, even though autoloader has loaded the file

所以我有一个目录可以反映我的命名空间结构。自动加载器正在正确加载包含我的 class 的文件。 use 子句使用别名指定了正确的 class。尽管如此,PHP 说找不到 class。我传统上不使用名称空间,因为这总是发生在我身上。但我试图强迫自己使用良好的做法。所以,我来这里是为了尝试理解为什么我无法让它工作。

我已经检查过自动加载器确实加载了文件。我已经检查了自动加载器使用的路径是否正确。

我的 class 文件:

<?php
namespace classes\helpers\core_helper;

class core_helper
{


  public static function create_arg_pairs($arguments)
  {
  .....
  }


}//end core_helper


?>  

我的主应用程序文件:

<?php

ini_set("display_errors", "1");

define('AUTH_ROOT', dirname(__FILE__));

use classes\helpers\core_helper as hlpr;


function autoloader($class)
{

  if(require_once AUTH_ROOT.'/'.str_replace('\','/',$class).'.php');

}
spl_autoload_register('autoloader');

......

$temp = explode("/", substr($path['path'], 1));
//get the controller
$contoller = strtolower(array_shift($temp));
//get the method
$method = strtolower(array_shift($temp));

$argArray = hlpr::create_arg_pairs($temp);


?>  

产生的错误是:

Fatal error: Uncaught Error: Class 'classes\helpers\core_helper' not found in /var/www/html/auth/index.php:51 Stack trace: #0 {main} thrown in /var/www/html/auth/index.php on line 51

但是我知道包含 class 的文件已加载,因此正确的命名空间被传递给自动加载器并且它被正确地转换为正确的路径。那为什么我看不到 class?

通过说

namespace classes\helpers\core_helper;

然后

class core_helper

您是在告诉系统您的实际 class 是 classes\helpers\core_helper\core_helper。我希望你真正想要的是 namespace classes\helpers;.