fix(php): 修复引用参数传递和模块命名问题

- 添加标量值作为引用参数时的错误检查
- 为动态调用类添加占位符处理
- 统一模块名称前缀为 app_
- 简化模块名称生成逻辑
- 添加动态调用测试用例
pull/1/head
韩天峰 4 months ago
parent 0293b28148
commit 608db0e8c2
  1. 5
      src/Php/CompilerBase.php
  2. 11
      src/Php/Translator.php
  3. 34
      tests/aot/dynamic_call/method-call.phpt

@ -2666,6 +2666,9 @@ class CompilerBase extends \PhpAot\Core\Translator
}
} else {
if ($byRef) {
if ($this->isScalar($arg->value)) {
$this->fatalError($arg, 'The constants cannot be used as an argument for a reference-type parameter');
}
$list_args[] = $this->parseChainedExpr($arg->value, self::OP_REFVAL);
continue;
}
@ -4145,6 +4148,8 @@ class CompilerBase extends \PhpAot\Core\Translator
return $object . '.call(' . $methodPtr . ')';
}
try {
// 类名为空,这是一个 var ,类型是 any ,编译期无法获得它的类型,需要动态调用
$class = empty($class) ? '__DYNAMIC-CALLED-CLASS__' : $class;
return $object . '.call(' . $methodPtr . ', ' . $this->parseCallArgs($expr->args, $funcName, $class) . ')';
} catch (PlaceHolder) {
return $this->genPlaceHolder($this->genArray([$object, $method]));

@ -46,6 +46,8 @@ class Translator extends Preprocessor
protected array $defaultPropertyList = [];
protected bool $useRegisterSymbolsFn = false;
protected const string MODULE_NAME_PREFIX = 'app_';
public function __construct(string $rootPath)
{
parent::__construct($rootPath);
@ -584,14 +586,7 @@ CODE;
public function getModuleName(): string
{
if (ctype_digit($this->targetName[0])) {
return 'app_' . $this->targetName;
}
$extensions = get_loaded_extensions();
if (in_array($this->targetName, $extensions)) {
return $this->targetName . '_';
}
return $this->targetName;
return self::MODULE_NAME_PREFIX . $this->targetName;
}
public function hasObjectFileCache(string $cppFile): bool

@ -0,0 +1,34 @@
--TEST--
named args
--FILE--
<?php
class FooObject
{
public function end($args)
{
var_dump($args);
}
}
function main()
{
$data = ['ae86', 'bmw',];
$object = new FooObject;
$object->end($data);
$array[] = $object;
$array[0]->end($data);
}
?>
--EXPECT--
array(2) {
[0]=>
string(4) "ae86"
[1]=>
string(3) "bmw"
}
array(2) {
[0]=>
string(4) "ae86"
[1]=>
string(3) "bmw"
}
Loading…
Cancel
Save