我不知道如何解释,但我会尽力而为。好的,我有这三个文件:
主题.php
path: /shared/models/Theme.php class: Theme namespace: namespace models;
自定义.php
path: /themes/default/Custom.php class: Custom namespace: this class does not use namespace
设置.php
path: /controllers/Settings.php class: Settings namespace: this class does not use namespace
在我Settings.php
看来:
<?php
class Settings
{
public function apply()
{
$theme = new \models\Theme();
$theme->customize(); // in this method the error is triggered
}
}
现在,看Theme
下面的类:
<?php
namespace models;
class Theme
{
public function customize()
{
$ext = "/themes/default/Custom.php";
if (file_exists($ext))
{
include $ext;
if (class_exists('Custom'))
{
$custom = new Custom();
//Here, $custom var in null, why???
}
}
}
}
当我执行代码时,我收到以下错误:
Message: require(/shared/models/Custom.php) [function.require]: failed to open stream: No such file or directory
Line Number: 64
为什么解释器试图Custom
从另一个目录加载类而不是用$ext
var 指定?