找不到PHP自动加载类
我的文件夹结构如下:找不到PHP自动加载类,php,autoload,Php,Autoload,我的文件夹结构如下: includes/ class-autoload.inc.php config/ classes/ admin.class.php admin/ clients.php admin.class.php是我试图使用的类文件。该文件包含 <?php class Admin extends Dbh{ . . . 不基于当前文件的位置解析相对路径,而是基于运行时的“工作目录” 要指定相对于
includes/
class-autoload.inc.php
config/
classes/
admin.class.php
admin/
clients.php
admin.class.php是我试图使用的类文件。该文件包含
<?php
class Admin extends Dbh{
.
.
.
不基于当前文件的位置解析相对路径,而是基于运行时的“工作目录” 要指定相对于当前文件的路径,请使用
\uuuuu DIR\uuuu
,例如
包括uuuu DIR.'//包括/class autoload.inc.php';
及
include_once uuu DIR_uu./../$路径$类名$扩展;
作为一个附加提示,如果您使用而不是include
,那么如果找不到该文件,您将得到一个错误,而不是默认失败
<?php
spl_autoload_register('myAutoLoader');
function myAutoLoader ($className){
$path = 'config/classes/';
$extension = '.class.php';
$fileName = $path . $className . $extension;
if(!file_exists($fileName)){
return false;
}
include_once $path . $className . $extension;
}
<?php
include '../includes/class-autoload.inc.php' ;
$admin = new Admin();
Fatal error: Uncaught Error: Class 'Admin' not found