【问题标题】:PHP extend class using namespaces fatal errorPHP使用命名空间扩展类致命错误
【发布时间】:2015-02-06 08:41:39
【问题描述】:

我有两节课。命名空间 test\bout\ 中的 Bout,命名空间 test\art 中的 Art。

namespace test\bout;
use test\art\Art;
class Bout extends Art{

    function __construct(){
        include_once 'Art.php';

        echo"boutique ";
        new Art();
    }
}
new Bout();

然后:

namespace test\art;
class Art{

    function __construct(){
        echo "article";
    }
}

只要我输入“扩展艺术”,我就有:致命错误:第 4 行的 /opt/lampp/htdocs/test/Boutique.php 中找不到类 'test\art\Art'

这是否意味着我没有使用“use test\art\Art;”正确吗?

谢谢

【问题讨论】:

  • 可能你没有类加载器或者你的文件夹架构无效并且不响应命名空间
  • 您是否真的包含定义test\art\Art的文件之前 class Bout extends ..

标签: php namespaces extends


【解决方案1】:

我发现了!

namespace test\bout;
use test\art\Art;
**include __DIR__.'/article/Article.php';**
class Bout extends Art{...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2014-09-18
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    相关资源
    最近更新 更多