【发布时间】:2012-10-25 15:06:51
【问题描述】:
我有一个在项目外部目录中命名空间的类。该目录包含在include_path 指令中。我想使用spl_autoload 类来自动加载该类。但是,我只会遇到错误。它似乎只是试图从项目目录加载文件。
这是一台 windows 机器,但我希望它可以在 windows 或 Linux 机器上工作
##incude_path directive##
include_path = ".;C:\xampp\php\PEAR;C:\Users\Joey\Dropbox\web\global_includes;C:\Users\Joey\Dropbox\web\global_includes\utility;C:\Users\Joey\Dropbox\web\global_includes\utility\arrayTools"
//index.php
require 'bootstrap.php';
$array = array('Hello','world');
$array[] = array('Hello','world','2');
$array[2][1] = array('Hello','world',3);
echo '<p>The number of dimesions: '.utility\arrayTools\arrayTools::numberOfDimensions($array).'</p>';
//bootstrap.php
spl_autoload_register('autoLoader::autoLoad');
class autoLoader
{
public static function autoLoad($file)
{
if(is_string($file)){
if(file_exists("$file.php")){
try{
include "$file.php";
}catch(Exception $exc){
echo '<pre><p>'.$exc->getMessage().'</p>'.$exc->getTraceAsString().'</pre>';
}
}
}
}
}
【问题讨论】:
-
Yaiks,静态 .. 不支持命名空间 .. 不支持路径 .. pffff ..
-
但是如果我将文件夹的副本移动到项目目录中,它就可以正常工作。所以由于某种原因,它只检查项目目录而不是所有的包含路径目录
-
所以我拿出了静态方法,同样的问题。就像它只在项目文件夹中查找一样。没有来自包含路径的路径
标签: php namespaces autoload spl-autoload-register spl-autoloader