2
我不知道如何解释它,但我会尽我所能。好吧,我有这三个文件:实例化一个对象到一个名字空间的类
Theme.php
path: /shared/models/Theme.php class: Theme namespace: namespace models;
Custom.php
path: /themes/default/Custom.php class: Custom namespace: this class does not use namespace
的settings.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?
是的,你是完全正确的。记住这一点非常重要:'因为你说你的自定义类没有名字空间,所以试试新的\ Custom()。“谢谢你:) – manix