PHP EMPTY token
define('EMPTY', '');
if(!empty(EMPTY))
{
if(!(boolean) _CONSTANT)
{
print "One";
}
}
The above code produces the following error message:
"Parse error: syntax error, unexpected 'EMPTY' (T_EMPTY) in C:UsersRobertDocumentsweb developmentxampphtdocsxamppweb_developmentindex.php on line 3"
Nowhere in the PHP Manual does it explicitly state that "EMPTY" is a token nor does it inform you about this pitfall.
函数名称不区分大小写。
$state = constant('EMPTY');
if (!empty($state)) {
You can declare constants with the same name as functions as PHP uses ()
to determine if a token is a function or constant declaration:
<?php
function myfunc() {
echo "inside myfunc()n";
}
define('str_replace', 'my string');
echo str_replace . "n";
echo str_replace("A", "B", "AAAA") . "n";
define('myfunc', 'this is myfunc constant');
echo myfunc . "n";
myfunc();
/*
Output:
my string
BBBB
this is myfunc constant
inside myfunc()
*/
This doesn't work for empty
because empty
is a language construct.
This isn't a problem... just pick another name for your constant.
If you would like, you can submit a documentation bug report.
链接地址: http://www.djcxy.com/p/59448.html上一篇: r,<pre>标记不起作用
下一篇: PHP EMPTY令牌