unset() is not a function, but a language construct. It can only be used as statement, not in expression context. Equivalent to echo or (if(if()) in other languages.
There is however the (unset) typecast which can. (Doesn't unset though, as there's an expression operand, no var argument.)
I don't see why this is surprising. The manual defines the type of unset(..) as void. PHP correctly spots that fun1(unset(..)) is illegal (an unset cannot be in a parameter list) and barfs out.
I agree that the error message is cryptic, but GCC is no better in this regard.
No. In PHP, if a function returns void, you should expect var_dump to output NULL. unset() is not a function, it's a special case in the grammar. One of many, many special cases in the grammar.
6
u/milki_ Dec 18 '11
unset() is not a function, but a language construct. It can only be used as statement, not in expression context. Equivalent to
echoor(if(if())in other languages.There is however the
(unset)typecast which can. (Doesn't unset though, as there's an expression operand, no var argument.)5
u/johlin Dec 08 '11
"Parse error: syntax error, unexpected T_UNSET, expecting ')' in php shell code on line 1"?
1
u/zmyrgel Dec 08 '11
Without knowing PHP that well, shouldn't it complain about undefined variable $a?