本文介绍了当给出非变量时,为什么空期望T_PAAMAYIM_NEKUDOTAYIM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
define('foo', 'bar');

if (empty(foo)) {
  echo 'qux';
}



我知道 empty()仅允许将变量作为参数传递,但是为什么当我给它一个常量时,为什么会期望一个T_PAAMAYIM_NEKUDOTAYIM(即 :: )?

I know that empty() only allows variables to be passed as an argument, but why does it expect a T_PAAMAYIM_NEKUDOTAYIM (i.e. ::) when I give it a constant?

推荐答案

解析器想要的下一个逻辑对象是 :: ,因为 foo 不是变量。

The next logical thing the parser wants is a :: because foo is not a variable.

if (empty(foo::$bar)) {
}

是唯一的事情,当 empty()没有传递变量时有效。您的示例被评估为 empty(bar),其中解析器假定 bar 是一个类名,现在期望一个静态成员变量。

Is the only thing, that works when empty() is not passed a variable. Your example is evaluated as empty(bar) where the parser assumes bar to be a class name and now expects a static member variable.

这篇关于当给出非变量时,为什么空期望T_PAAMAYIM_NEKUDOTAYIM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 13:23