Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Zend/tests/assert/expect_015.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ assert(0 && ($a = function &(array &$a, ?X $b = null) use($c, &$d): ?X {
$s[$i] = $a[$j];
}
foreach ($a as $key => &$val) {
print "$key => $val\n";
print "{$key} => {$val}\n";
}
while ($s[$i]) {
$i++;
Expand Down Expand Up @@ -299,12 +299,12 @@ assert(0 && ($a = function (): ?static {
echo 1;
}
$x = '\'"`$a';
$x = "'\"`$a";
$x = `'"\`$a`;
$x = "'\"`{$a}";
$x = `'"\`{$a}`;
$x = "{$a}b";
$x = "{$a}b";
$x = " {$foo->bar} {${$foo->bar}} ";
$x = " ${---} ";
$x = " {${---}} ";
foo();
\foo();
namespace\foo();
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/assert/expect_020.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ assert(0 && ($a = function () {
--EXPECT--
assert(): assert(0 && ($a = function () {
$var = 'test';
$str = "$var, {$var[1]}, {$var}[], {$var[1]}[], {$var}[], {$var[1]}[]";
$str = "{$var}, {$var[1]}, {$var}[], {$var[1]}[], {$var}[], {$var[1]}[]";
})) failed
26 changes: 0 additions & 26 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,19 +1367,6 @@ static ZEND_COLD void zend_ast_export_ns_name(smart_str *str, zend_ast *ast, int
zend_ast_export_ex(str, ast, priority, indent);
}

static ZEND_COLD bool zend_ast_valid_var_char(char ch)
{
unsigned char c = (unsigned char)ch;

if (c != '_' && c < 127 &&
(c < '0' || c > '9') &&
(c < 'A' || c > 'Z') &&
(c < 'a' || c > 'z')) {
return 0;
}
return 1;
}

static ZEND_COLD bool zend_ast_valid_var_name(const char *s, size_t len)
{
unsigned char c;
Expand All @@ -1406,11 +1393,6 @@ static ZEND_COLD bool zend_ast_valid_var_name(const char *s, size_t len)
return 1;
}

static ZEND_COLD bool zend_ast_var_needs_braces(char ch)
{
return ch == '[' || zend_ast_valid_var_char(ch);
}

static ZEND_COLD void zend_ast_export_var(smart_str *str, zend_ast *ast, int priority, int indent)
{
if (ast->kind == ZEND_AST_ZVAL) {
Expand Down Expand Up @@ -1454,14 +1436,6 @@ static ZEND_COLD void zend_ast_export_encaps_list(smart_str *str, char quote, ze

ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
zend_ast_export_qstr(str, quote, Z_STR_P(zv));
} else if (ast->kind == ZEND_AST_VAR &&
ast->child[0]->kind == ZEND_AST_ZVAL &&
(i + 1 == list->children ||
list->child[i + 1]->kind != ZEND_AST_ZVAL ||
!zend_ast_var_needs_braces(
*Z_STRVAL_P(
zend_ast_get_zval(list->child[i + 1]))))) {
zend_ast_export_ex(str, ast, 0, indent);
} else {
smart_str_appendc(str, '{');
zend_ast_export_ex(str, ast, 0, indent);
Expand Down
19 changes: 19 additions & 0 deletions ext/standard/tests/assert/gh22291.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
GH-22291: AST pretty printing does not correctly handle braces in string interpolation
--FILE--
<?php

try {
$foo = 'abc';
var_dump("{{$foo}}");
var_dump("{$foo}");
assert(!"{{$foo}}");
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
string(5) "{abc}"
string(3) "abc"
assert(!"{{$foo}}")
Loading