From 8517481c52e0a783e092e2e0e323ac32d0d1fd99 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 12 Jun 2026 17:43:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E6=AD=A3print=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E7=BC=96=E8=AF=91=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将php::echo改为php::print以正确处理print表达式 - 添加完整的print函数测试用例验证功能正确性 --- src/Php/CompilerBase.php | 2 +- tests/aot/functions/print.phpt | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/aot/functions/print.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 55061c2d..af85c588 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3178,7 +3178,7 @@ class CompilerBase extends \PhpAot\Core\Translator protected function parsePrint(Expr\Print_ $expr): string { - return 'php::echo(' . $this->parseExpr($expr->expr) . ')'; + return 'php::print(' . $this->parseExpr($expr->expr) . ')'; } protected function parseDo(Node\Stmt\Do_ $v): string diff --git a/tests/aot/functions/print.phpt b/tests/aot/functions/print.phpt new file mode 100644 index 00000000..ec512144 --- /dev/null +++ b/tests/aot/functions/print.phpt @@ -0,0 +1,30 @@ +--TEST-- +any +--FILE-- +p); + } +} + +readonly class B implements I { + function __construct(private array $i) {} + function o(): string { + return sprintf("%d its", count($this->i)); + } +} + +function main(): void { + $x = [new G(1999.99), new B(["A","B","C"])]; + array_map(fn(I $i) => print($i->o() . "\n"), $x); +} +?> +--EXPECT-- +$1999.99 +3 its