【问题标题】:PHP 5.4 does not recognize parent constantPHP 5.4 不识别父常量
【发布时间】:2015-07-09 00:44:13
【问题描述】:

我迁移了我的云服务器,在安装了所有灯的东西并克隆了我的存储库后,我的 php 无法识别“父”常量。

我的日志说。

[2015 年 7 月 8 日星期三 21:29:28] [错误] [客户端 186.223.169.223] PHP 注意:使用未定义的常量父级 - 在 /home/dev/xxx/Funcionario.php 第 11 行中假定为“父级” , 引用者:xxx

在代码中我有

class Funcionario extends Model {

    protected function init() {
        $this -> db = DataBase::getInstance('000001');

        call_user_func_array(array( parent, 'init'), func_get_args() );
    }
}

观察。 PHP-5.4

谢谢。

【问题讨论】:

  • 什么?你为什么这么称呼它,只做 parent::init(),你没有 args 可担心。
  • @ArtisiticPhoenix 除了Funcionario::init() 可以使用超出声明中的参数调用;因此使用func_get_args()

标签: php php-5.4


【解决方案1】:

使用未定义的常量父级 - 假定为“父级”

这是因为parent 后面没有跟范围运算符:: 被认为是一个常量;如果你把它变成一个字符串,它就可以正常工作:

call_user_func_array(array('parent', 'init'), func_get_args());

没有它也可以正常工作,您现在看到该通知的唯一原因是因为 error_reporting 级别不同。

【讨论】:

  • 谢谢。 15分钟后我意识到了这一点,但忘了在这里回答。
猜你喜欢
  • 2014-12-22
  • 1970-01-01
  • 2022-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-29
  • 1970-01-01
相关资源
最近更新 更多