mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-07-12 18:06:46 +02:00
Allow expressions in isset()
Partial fix for #653. PHP 7 allows expressions inside isset(), but rejects non-variables in the compiler. A side-effect of this is that isset(($x)) is allowed, though this is not intentional.
This commit is contained in:
@ -232,7 +232,7 @@ non_empty_statement:
|
|||||||
| T_RETURN optional_expr semi { $$ = Stmt\Return_[$2]; }
|
| T_RETURN optional_expr semi { $$ = Stmt\Return_[$2]; }
|
||||||
| T_GLOBAL global_var_list semi { $$ = Stmt\Global_[$2]; }
|
| T_GLOBAL global_var_list semi { $$ = Stmt\Global_[$2]; }
|
||||||
| T_STATIC static_var_list semi { $$ = Stmt\Static_[$2]; }
|
| T_STATIC static_var_list semi { $$ = Stmt\Static_[$2]; }
|
||||||
| T_ECHO expr_list semi { $$ = Stmt\Echo_[$2]; }
|
| T_ECHO expr_list_forbid_comma semi { $$ = Stmt\Echo_[$2]; }
|
||||||
| T_INLINE_HTML { $$ = Stmt\InlineHTML[$1]; }
|
| T_INLINE_HTML { $$ = Stmt\InlineHTML[$1]; }
|
||||||
| expr semi { $$ = Stmt\Expression[$1]; }
|
| expr semi { $$ = Stmt\Expression[$1]; }
|
||||||
| T_UNSET '(' variables_list ')' semi { $$ = Stmt\Unset_[$3]; }
|
| T_UNSET '(' variables_list ')' semi { $$ = Stmt\Unset_[$3]; }
|
||||||
@ -632,10 +632,14 @@ property_declaration:
|
|||||||
| property_decl_name '=' expr { $$ = Stmt\PropertyProperty[$1, $3]; }
|
| property_decl_name '=' expr { $$ = Stmt\PropertyProperty[$1, $3]; }
|
||||||
;
|
;
|
||||||
|
|
||||||
expr_list:
|
expr_list_forbid_comma:
|
||||||
non_empty_expr_list no_comma { $$ = $1; }
|
non_empty_expr_list no_comma { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
expr_list_allow_comma:
|
||||||
|
non_empty_expr_list optional_comma { $$ = $1; }
|
||||||
|
;
|
||||||
|
|
||||||
non_empty_expr_list:
|
non_empty_expr_list:
|
||||||
non_empty_expr_list ',' expr { push($1, $3); }
|
non_empty_expr_list ',' expr { push($1, $3); }
|
||||||
| expr { init($1); }
|
| expr { init($1); }
|
||||||
@ -643,7 +647,7 @@ non_empty_expr_list:
|
|||||||
|
|
||||||
for_expr:
|
for_expr:
|
||||||
/* empty */ { $$ = array(); }
|
/* empty */ { $$ = array(); }
|
||||||
| expr_list { $$ = $1; }
|
| expr_list_forbid_comma { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
expr:
|
expr:
|
||||||
@ -706,7 +710,7 @@ expr:
|
|||||||
| expr '?' expr ':' expr { $$ = Expr\Ternary[$1, $3, $5]; }
|
| expr '?' expr ':' expr { $$ = Expr\Ternary[$1, $3, $5]; }
|
||||||
| expr '?' ':' expr { $$ = Expr\Ternary[$1, null, $4]; }
|
| expr '?' ':' expr { $$ = Expr\Ternary[$1, null, $4]; }
|
||||||
| expr T_COALESCE expr { $$ = Expr\BinaryOp\Coalesce[$1, $3]; }
|
| expr T_COALESCE expr { $$ = Expr\BinaryOp\Coalesce[$1, $3]; }
|
||||||
| T_ISSET '(' variables_list ')' { $$ = Expr\Isset_[$3]; }
|
| T_ISSET '(' expr_list_allow_comma ')' { $$ = Expr\Isset_[$3]; }
|
||||||
| T_EMPTY '(' expr ')' { $$ = Expr\Empty_[$3]; }
|
| T_EMPTY '(' expr ')' { $$ = Expr\Empty_[$3]; }
|
||||||
| T_INCLUDE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE]; }
|
| T_INCLUDE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE]; }
|
||||||
| T_INCLUDE_ONCE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE_ONCE]; }
|
| T_INCLUDE_ONCE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE_ONCE]; }
|
||||||
|
File diff suppressed because it is too large
Load Diff
49
test/code/parser/expr/exprInIsset.test
Normal file
49
test/code/parser/expr/exprInIsset.test
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
Expressions in isset()
|
||||||
|
-----
|
||||||
|
<?php
|
||||||
|
// This is legal.
|
||||||
|
isset(($a), (($b)));
|
||||||
|
// This is illegal, but not a syntax error.
|
||||||
|
isset(1 + 1);
|
||||||
|
-----
|
||||||
|
!!php7
|
||||||
|
array(
|
||||||
|
0: Stmt_Expression(
|
||||||
|
expr: Expr_Isset(
|
||||||
|
vars: array(
|
||||||
|
0: Expr_Variable(
|
||||||
|
name: a
|
||||||
|
)
|
||||||
|
1: Expr_Variable(
|
||||||
|
name: b
|
||||||
|
)
|
||||||
|
)
|
||||||
|
comments: array(
|
||||||
|
0: // This is legal.
|
||||||
|
)
|
||||||
|
)
|
||||||
|
comments: array(
|
||||||
|
0: // This is legal.
|
||||||
|
)
|
||||||
|
)
|
||||||
|
1: Stmt_Expression(
|
||||||
|
expr: Expr_Isset(
|
||||||
|
vars: array(
|
||||||
|
0: Expr_BinaryOp_Plus(
|
||||||
|
left: Scalar_LNumber(
|
||||||
|
value: 1
|
||||||
|
)
|
||||||
|
right: Scalar_LNumber(
|
||||||
|
value: 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
comments: array(
|
||||||
|
0: // This is illegal, but not a syntax error.
|
||||||
|
)
|
||||||
|
)
|
||||||
|
comments: array(
|
||||||
|
0: // This is illegal, but not a syntax error.
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
Reference in New Issue
Block a user