diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 8822bb52..ee07e228 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2073,18 +2073,16 @@ class CompilerBase extends \PhpAot\Core\Translator $attr = $expr->getAttribute('stdContainerDimFetch'); return $this->context->stdContainers[$attr['var']]['class'] ?? ''; } + if ($this->isFuncCallExpr($expr) and $this->isNameExpr($expr->name)) { + $fn = $this->parseIdentifier($expr->name); + if (count($expr->args) === 2 and $fn === 'objval') { + return $this->resolveClassNameArg($expr->args[1]->value); + } + } if ($this->isMethodCall($expr) and $this->isNamedMethod($expr->name)) { $method = $this->parseIdentifier($expr->name); if ($method === 'toObject' and !empty($expr->args)) { - $argClass = $expr->args[0]->value; - if ($this->isScalarString($argClass)) { - return $this->getNamespacedClassName($argClass->value); - } - if ($this->isClassConstFetch($argClass)) { - if ($this->isNameExpr($argClass->class) and $this->isIdExpr($argClass->name) and $this->parseIdentifier($argClass->name) === 'class') { - return $this->getNamespacedClassName($this->parseIdentifier($argClass->class)); - } - } + return $this->resolveClassNameArg($expr->args[0]->value); } if ($this->isVarExpr($expr->var)) { $object = $this->parseVariable($expr->var); @@ -2114,6 +2112,19 @@ class CompilerBase extends \PhpAot\Core\Translator return ''; } + protected function resolveClassNameArg(NodeAbstract $arg): string + { + if ($this->isScalarString($arg)) { + return $this->getNamespacedClassName($arg->value); + } + if ($this->isClassConstFetch($arg)) { + if ($this->isNameExpr($arg->class) and $this->isIdExpr($arg->name) and $this->parseIdentifier($arg->name) === 'class') { + return $this->getNamespacedClassName($this->parseIdentifier($arg->class)); + } + } + return ''; + } + protected function parseReturn(Node\Stmt\Return_ $v): string { if ($v->expr === null) { diff --git a/src/polyfills.php b/src/polyfills.php index fb16acdf..5ba32f53 100644 --- a/src/polyfills.php +++ b/src/polyfills.php @@ -89,3 +89,8 @@ function any(mixed $var): mixed return $var; } +function objval(mixed $var, string $className): mixed +{ + return $var; +} +