简体   繁体   English

致命错误php-意外')'

[英]FATAL ERROR php - unexpected ')'

this code gives me the error : 此代码给我错误:

FATAL ERROR syntax error, unexpected ')', expecting '(' on line number 10 -- line 10 is this one: "if ( ! empty( EMPTY ) ) { " 致命错误语法错误,意外的')',在第10行-第10行上的期望是(('),是这样的:“ if(!empty(EMPTY)){

I don't get it...could you help explaining? 我不明白...您能帮忙解释一下吗?

define('CONSTANT', 1);

define('_CONSTANT', 0);

define('EMPTY','');

if  ( ! empty( EMPTY ) ) {

    if ( ! ( ( boolean ) _CONSTANT ) ) {

        print "One";

    }

} else if ( constant( 'CONSTANT' == 1 )) {

    print "TWO";

}

In PHP method names are case-insensitive. 在PHP中,方法名称不区分大小写。 For example, these statements are doing the same thing: 例如,这些语句执行相同的操作:

echo empty(0);
//out: 1
echo emPTY(0);
//out: 1
echo EMPTY(0);
//out: 1

You are trying to define a constant that has the same name as built-in PHP method empty . 您正在尝试定义一个与内置PHP方法empty相同名称的常量。 When you call empty(EMPTY) (which is the same as empty(empty) PHP thinks that you are trying to call (outer) empty on result of (inner) EMPTY invocation, but oops, your inner EMPTY is not a method invocation at all (it misses the braces). During building AST PHP expects something like empty(EMPTY(...)) (note the open brace after inner EMPTY ) and that's why you are getting syntax error expecting "("... . 当您调用empty(EMPTY) (与empty(empty)相同empty(empty) PHP认为您试图在(内部) EMPTY调用的结果上调用(外部)为empty ,但是,哎呀,您的内部EMPTY并不是方法调用在构建AST的过程中,PHP期望empty(EMPTY(...)) (注意内部EMPTY之后的大括号),这就是为什么语法错误的原因是expecting "("...

Use defined because empty check variables and you are checking on constants. 使用defined因为检查变量为empty并且您正在检查常量。 defined — Checks whether a given named constant exists. defined —检查是否存在给定的命名常量。 As its said here defined Documentation 如其所定义的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM