Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Zend/tests/assert/expect_015.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ assert(0 && ($a = function (): ?static {
$x = "{$a}b";
$x = "{$a}b";
$x = " {$foo->bar} {${$foo->bar}} ";
$x = " ${---} ";
$x = " ${'---'} ";
foo();
\foo();
namespace\foo();
Expand Down
11 changes: 8 additions & 3 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1415,9 +1415,14 @@ static ZEND_COLD void zend_ast_export_var(smart_str *str, zend_ast *ast, int pri
{
if (ast->kind == ZEND_AST_ZVAL) {
zval *zv = zend_ast_get_zval(ast);
if (Z_TYPE_P(zv) == IS_STRING &&
zend_ast_valid_var_name(Z_STRVAL_P(zv), Z_STRLEN_P(zv))) {
smart_str_append(str, Z_STR_P(zv));
if (Z_TYPE_P(zv) == IS_STRING) {
if (zend_ast_valid_var_name(Z_STRVAL_P(zv), Z_STRLEN_P(zv))) {
smart_str_append(str, Z_STR_P(zv));
} else {
smart_str_appends(str, "{'");
zend_ast_export_str(str, Z_STR_P(zv));
smart_str_appends(str, "'}");
}
return;
}
} else if (ast->kind == ZEND_AST_VAR) {
Expand Down
31 changes: 31 additions & 0 deletions ext/standard/tests/assert/gh22292.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
GH-22292: AST pretty printing does not correctly handle invalid variable names
--FILE--
<?php

class Foo {
public function __get($name) { return $name; }
}

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

try {
$f = new Foo();
var_dump($f->{'---'});
assert(!$f->{'---'});
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

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