Skip to content

Commit

Permalink
Implement #72918: negative offset inside a quoted string leads to par…
Browse files Browse the repository at this point in the history
…se error

We allow negative numeric offsets for the simple syntax inside
double-quoted and heredoc strings.
  • Loading branch information
cmb69 committed Oct 14, 2016
1 parent 6e3ab61 commit 2cc3aeb
Show file tree
Hide file tree
Showing 6 changed files with 3,979 additions and 4,119 deletions.
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ PHP 7.1 UPGRADE NOTES
type declarations, and some internal functions. Both nullable type
declarations (?int) and parameters with default values of null
(int $foo = NULL) are considered to "accept null" for this purpose.
. The simple syntax for variable parsing inside of string literals now
supports negative offsets.

========================================
3. Changes in SAPI modules
Expand Down
22 changes: 22 additions & 0 deletions Zend/tests/bug72918.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Bug #72918 (negative offset inside a quoted string leads to parse error)
--FILE--
<?php
$array = [-3 => 'foo'];
$string = 'abcde';

echo "$array[-3]\n";
echo "$string[-3]\n";
echo <<<EOT
$array[-3]
$string[-3]
EOT;
?>
===DONE===
--EXPECT--
foo
c
foo
c
===DONE===
1 change: 1 addition & 0 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,7 @@ encaps_var:
encaps_var_offset:
T_STRING { $$ = $1; }
| T_NUM_STRING { $$ = $1; }
| '-' T_NUM_STRING { $$ = zend_ast_create(ZEND_AST_UNARY_MINUS, $2); }
| T_VARIABLE { $$ = zend_ast_create(ZEND_AST_VAR, $1); }
;

Expand Down
Loading

0 comments on commit 2cc3aeb

Please sign in to comment.