diff --git a/examples/const_expr.php b/examples/const_expr.php new file mode 100644 index 00000000..9c7a960b --- /dev/null +++ b/examples/const_expr.php @@ -0,0 +1,22 @@ +isPassedByReference(); + } + protected function parseCallArgs(array $args, string $funcName = '', string $className = ''): string { $list_args = []; @@ -3028,7 +3043,7 @@ class CompilerBase extends \PhpAot\Core\Translator if ($arg->name !== null) { return $this->parseNamedCallArgs($args, $i, $list_args); } - $byRef = $funcName && Reflection::isReferenceArg($funcName, $className, $i); + $byRef = $funcName && $this->isReferenceArgument($funcName, $className, $i); if ($this->isVarExpr($arg->value)) { $name = $this->parseIdentifier($arg->value); if ($byRef) { @@ -4596,7 +4611,7 @@ class CompilerBase extends \PhpAot\Core\Translator } try { // 类名为空,这是一个 var ,类型是 any ,编译期无法获得它的类型,需要动态调用 - $class = empty($class) ? '__DYNAMIC-CALLED-CLASS__' : $class; + $class = empty($class) ? self::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/Reflection.php b/src/Php/Reflection.php index 863232d1..6756a3a9 100644 --- a/src/Php/Reflection.php +++ b/src/Php/Reflection.php @@ -153,19 +153,6 @@ class Reflection return $args[$index]; } - public static function isReferenceArg(string $fnName, string $className, int $index): ?string - { - if ($className) { - $param = self::getClassMethodParameter($className, $fnName, $index); - } else { - $param = self::getFunctionParameter($fnName, $index); - } - if (!$param) { - return null; - } - return $param->isPassedByReference() ? $param->getName() : null; - } - public static function hasMethod(string $extends, string $method): bool { $class = self::getClass($extends); diff --git a/src/gen_stub.php b/src/gen_stub.php index 4eb70b78..bf18b7aa 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -2324,13 +2324,14 @@ class EvaluatedValue } } - foreach ($allConstInfos as $const) { - if ($constName != $const->cValue) { + foreach ($allConstInfos as $name => $const) { + if ($constName != $name) { continue; } $constType = ($const->phpDocType ?? $const->type)->tryToSimpleType(); if ($constType) { + // 这里返回的并不是真正的值,而是一个类型的占位符,最终的运算由编译器完成,此处仅用于 ArgInfo 处理 if ($constType->isBool()) { return true; } elseif ($constType->isInt()) { @@ -2338,7 +2339,6 @@ class EvaluatedValue } elseif ($constType->isFloat()) { return M_PI; } elseif ($constType->isString()) { - var_dump($const); return $const->name; } elseif ($constType->isArray()) { return [];