summaryrefslogtreecommitdiff
path: root/Zend/zend_language_parser.y
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2012-04-12 11:54:52 +0200
committerNikita Popov <nikic@php.net>2012-05-13 14:56:51 +0200
commitec061a93c53c8cde10237741e98e992c1a05d148 (patch)
tree443c1b193db39a901d5540543bcbaa012ef76c8c /Zend/zend_language_parser.y
parent5852e5f48d7b013108b98b9c57c18383765d21ea (diff)
downloadphp-git-ec061a93c53c8cde10237741e98e992c1a05d148.tar.gz
Allow arbitrary expressions for empty()
This change is as per RFC https://wiki.php.net/rfc/empty_isset_exprs. The change allows passing the result of function calls and other expressions to the empty() language construct. This is accomplished by simply rewriting empty(expr) to !expr. The change does not affect the suppression of errors when using empty() on variables. empty($undefinedVar) will continue not to throw errors. When an expression is used inside empty() on the other hand, errors will not be suppressed. Thus empty($undefinedVar + $somethingElse) *will* throw a notice. The change also does not make empty() into a real function, so using 'empty' as a callback is still not possible. In addition to the empty() changes the commit adds nicer error messages when isset() is used on function call results or other expressions.
Diffstat (limited to 'Zend/zend_language_parser.y')
-rw-r--r--Zend/zend_language_parser.y10
1 files changed, 8 insertions, 2 deletions
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 893e0133ef..5a5bb60cfb 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -1158,6 +1158,7 @@ encaps_var_offset:
internal_functions_in_yacc:
T_ISSET '(' isset_variables ')' { $$ = $3; }
| T_EMPTY '(' variable ')' { zend_do_isset_or_isempty(ZEND_ISEMPTY, &$$, &$3 TSRMLS_CC); }
+ | T_EMPTY '(' expr_without_variable ')' { zend_do_unary_op(ZEND_BOOL_NOT, &$$, &$3 TSRMLS_CC); }
| T_INCLUDE expr { zend_do_include_or_eval(ZEND_INCLUDE, &$$, &$2 TSRMLS_CC); }
| T_INCLUDE_ONCE expr { zend_do_include_or_eval(ZEND_INCLUDE_ONCE, &$$, &$2 TSRMLS_CC); }
| T_EVAL '(' expr ')' { zend_do_include_or_eval(ZEND_EVAL, &$$, &$3 TSRMLS_CC); }
@@ -1166,8 +1167,13 @@ internal_functions_in_yacc:
;
isset_variables:
- variable { zend_do_isset_or_isempty(ZEND_ISSET, &$$, &$1 TSRMLS_CC); }
- | isset_variables ',' { zend_do_boolean_and_begin(&$1, &$2 TSRMLS_CC); } variable { znode tmp; zend_do_isset_or_isempty(ZEND_ISSET, &tmp, &$4 TSRMLS_CC); zend_do_boolean_and_end(&$$, &$1, &tmp, &$2 TSRMLS_CC); }
+ isset_variable { $$ = $1; }
+ | isset_variables ',' { zend_do_boolean_and_begin(&$1, &$2 TSRMLS_CC); } isset_variable { zend_do_boolean_and_end(&$$, &$1, &$4, &$2 TSRMLS_CC); }
+;
+
+isset_variable:
+ variable { zend_do_isset_or_isempty(ZEND_ISSET, &$$, &$1 TSRMLS_CC); }
+ | expr_without_variable { zend_error(E_COMPILE_ERROR, "Cannot use isset() on the result of an expression (you can use \"null !== expression\" instead)"); }
;
class_constant: