Skip to content

Commit 24e365f

Browse files
committed
Make encapsed strings fully dereferencable
This allows operations that were previously allowed on constant strings on interpolated strings as well.
1 parent d933591 commit 24e365f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Dereferencing operations on an encapsed string
3+
--FILE--
4+
<?php
5+
6+
$bar = "bar";
7+
var_dump("foo$bar"[0]);
8+
var_dump("foo$bar"->prop);
9+
try {
10+
var_dump("foo$bar"->method());
11+
} catch (Error $e) {
12+
echo $e->getMessage(), "\n";
13+
}
14+
15+
class FooBar { public static $prop = 42; }
16+
var_dump("foo$bar"::$prop);
17+
18+
function foobar() { return 42; }
19+
var_dump("foo$bar"());
20+
21+
?>
22+
--EXPECTF--
23+
string(1) "f"
24+
25+
Warning: Trying to get property 'prop' of non-object in %s on line %d
26+
NULL
27+
Call to a member function method() on string
28+
int(42)
29+
int(42)

Zend/zend_language_parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ dereferencable_scalar:
11021102
T_ARRAY '(' array_pair_list ')' { $$ = $3; $$->attr = ZEND_ARRAY_SYNTAX_LONG; }
11031103
| '[' array_pair_list ']' { $$ = $2; $$->attr = ZEND_ARRAY_SYNTAX_SHORT; }
11041104
| T_CONSTANT_ENCAPSED_STRING { $$ = $1; }
1105+
| '"' encaps_list '"' { $$ = $2; }
11051106
;
11061107

11071108
scalar:
@@ -1118,7 +1119,6 @@ scalar:
11181119
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC { $$ = $2; }
11191120
| T_START_HEREDOC T_END_HEREDOC
11201121
{ $$ = zend_ast_create_zval_from_str(ZSTR_EMPTY_ALLOC()); }
1121-
| '"' encaps_list '"' { $$ = $2; }
11221122
| T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = $2; }
11231123
| dereferencable_scalar { $$ = $1; }
11241124
| constant { $$ = $1; }

0 commit comments

Comments
 (0)