PHP 访问由其他命名空间元素生成的对象

标签 php properties namespaces

关闭。这个问题需要debugging details .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

2年前关闭。




Improve this question




我在命名空间中有一个类,它通过从另一个命名空间导入的另一个类加载 json 文件

use *\*\file\json_datas as file;

然后在一种方法中,我通过实例化文件类来加载文件,没有问题
    private function load_json(){

    $this->settings["json"] = new file($this->settings["file"],false,false);

    $this->content["json"] = new file($this->content["file"],false,false);

在这一点上, $this->content["json"] 的输出返回了我所期望的,或者
*\*\file\json_datas Object
(
    [file] => en.json
    [name] => en
    [extension] => json
    [folder] => ####
    [fullpath] => /#####/
    [datas] => stdClass Object
        (
            [head] => stdClass Object
                (
                    [title] => Array

但是当我想直接引用 head 时出现我的问题,如下所示
$this->head =& $this->content["json"]->datas->head;

两者都不
$this->head =& $this->content["json"]["datas"]["head"];

$this->head 的输出是空白的,并且(在 E_ALL 有 error_reporting)我没有记录任何错误/通知。任何的想法 ?

最佳答案

我找到了原因。
语法没有问题,只是文件类的 datas 属性被定义为私有(private)。
我是新来的,我不知道我是否应该离开这个帖子,以防万一它对其他人有用...

关于PHP 访问由其他命名空间元素生成的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59305984/

相关文章:

java - 通过 Spring by Environment 注入(inject)属性值

java - 如何在不下载的情况下获取文件属性

javascript - 获取所有用户定义的窗口属性?

php - 在php中自定义日期格式到mysql

php - mysqli 在函数内准备好语句

php - JSON 数组到表 Sonata 管理包

php - PHP更新不起作用

class - 如何将 htmlpurifier 与 symfony2 集成?

Java+DOM : How do I set the base namespace of an (already created) Document?

.NET XmlDocument : Including default namespace prefixes in OuterXml