diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 8437e1d1..2ff0d9ca 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -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])); diff --git a/src/Php/Translator.php b/src/Php/Translator.php index c2ae1a36..c2dc9a2d 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -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 diff --git a/tests/aot/dynamic_call/method-call.phpt b/tests/aot/dynamic_call/method-call.phpt new file mode 100644 index 00000000..6f1d32ec --- /dev/null +++ b/tests/aot/dynamic_call/method-call.phpt @@ -0,0 +1,34 @@ +--TEST-- +named args +--FILE-- +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" +} \ No newline at end of file