fix(php): 修复数组类型返回和include表达式处理

- 将 Expr_Array 的类型返回从 'php::Array' 改为 self::TYPE_ARRAY
- 将字符串 'array' 的类型映射从 'php::Array' 改为 self::TYPE_ARRAY
- 更新 parseInclude 方法参数类型为 Node\Expr\Include_
- 添加对不同 include 类型 (include, require, include_once, require_once) 的支持
- 在 include 表达式中传递正确的类型参数
- 添加 include 测试用例和相关测试文件
pull/1/head
韩天峰 7 months ago
parent f38098523f
commit d3360d2f38
  1. 24
      src/Php/CompilerBase.php
  2. 12
      tests/aot/include.phpt
  3. 2
      tests/aot/test_include.inc

@ -1052,7 +1052,7 @@ class CompilerBase extends \PhpAot\Core\Translator
case 'Scalar_Bool':
return self::TYPE_BOOL;
case 'Expr_Array':
return 'php::Array';
return self::TYPE_ARRAY;
case 'Expr_BinaryOp_Plus':
case 'Expr_BinaryOp_Minus':
case 'Expr_BinaryOp_Mul':
@ -1151,7 +1151,7 @@ class CompilerBase extends \PhpAot\Core\Translator
case 'int':
return self::TYPE_INT;
case 'array':
return 'php::Array';
return self::TYPE_ARRAY;
case 'float':
return self::TYPE_FLOAT;
case 'bool':
@ -2317,9 +2317,25 @@ class CompilerBase extends \PhpAot\Core\Translator
return 'php::eval(' . $this->parseIdentifier($expr->expr) . ')';
}
protected function parseInclude(mixed $expr): string
protected function parseInclude(Node\Expr\Include_ $expr): string
{
return 'php::include(' . $this->parseIdentifier($expr->expr) . ')';
switch ($expr->type) {
case Node\Expr\Include_::TYPE_INCLUDE:
$type = 'php::INCLUDE';
break;
case Node\Expr\Include_::TYPE_INCLUDE_ONCE:
$type = 'php::INCLUDE_ONCE';
break;
case Node\Expr\Include_::TYPE_REQUIRE:
$type = 'php::REQUIRE';
break;
case Node\Expr\Include_::TYPE_REQUIRE_ONCE:
$type = 'php::REQUIRE_ONCE';
break;
default:
$this->fatalError($expr, 'Invalid include type');
}
return 'php::include(' . $this->parseIdentifier($expr->expr) . ', '. $type . ')';
}
protected function parseBreak(mixed $v): string

@ -0,0 +1,12 @@
--TEST--
strlen
--FILE--
<?php
include __DIR__ . '/test_include.inc';
require __DIR__ . '/test_include.inc';
include_once __DIR__ . '/test_include.inc';
require_once __DIR__ . '/test_include.inc';
?>
--EXPECT--
test_include.inc
test_include.inc

@ -0,0 +1,2 @@
<?php
echo basename(__FILE__) . "\n";
Loading…
Cancel
Save