Reputation: 5074
AFAIK empty and isset are normal php functions. When I try the following I get a parse error
if (\empty($array)) {
// .....
}
PHP Parse error: syntax error, unexpected 'empty' (T_EMPTY), expecting identifier (T_STRING) in
This seems strange to me because other php functions http://php.net/manual/en/ref.var.php such as \is_array
, \is_null
, \is_object
, \strpos
etc... allow backslash.
Why are these (at least) two functions different?
Upvotes: 3
Views: 2546
Reputation: 522016
They are not. They are language constructs, which you can read as keywords. If they would play by the normal rules of functions, they couldn't do what they are doing. isset($foo)
would always trigger an error about undefined variables, since PHP would try to resolve the variable $foo
before passing its value to the function isset
. That is clearly against what those language constructs are supposed to do.
Upvotes: 16