fix(php): 修正print函数的编译输出

- 将php::echo改为php::print以正确处理print表达式
- 添加完整的print函数测试用例验证功能正确性
pull/1/head
韩天峰 2 months ago
parent 58f45fe97a
commit 8517481c52
  1. 2
      src/Php/CompilerBase.php
  2. 30
      tests/aot/functions/print.phpt

@ -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

@ -0,0 +1,30 @@
--TEST--
any
--FILE--
<?php
declare(strict_types=1);
interface I { function o(): string; }
readonly class G implements I {
function __construct(private float $p) {}
function o(): string {
return sprintf("$%.2f", $this->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
Loading…
Cancel
Save