diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 4eaded66..e07e9d53 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1423,9 +1423,9 @@ class CompilerBase extends \PhpAot\Core\Translator $list = []; $list[] = $this->getIndent() . $tmpVar . ' = ' . $this->parseExpr($next); - $right = new Variable($tmpVar); + $rightVar = new Variable($tmpVar); foreach ($chain as $var) { - $list[] = $this->getIndent() . $this->parseAssignFinally($var, $right); + $list[] = $this->getIndent() . $this->parseAssignFinally($var, $rightVar); } return implode(";\n" . $this->getIndent(), $list); @@ -2349,7 +2349,7 @@ class CompilerBase extends \PhpAot\Core\Translator } $class = ''; $type = $this->parseTypeDecl($param->type, self::DECL_TYPE_OF_PARAM, $class); - if ($class) { + if ($class and !$this->hasInterface($class) and !$this->isAbstractClass($class)) { $this->addObject($var, $class); $argInfo->class = $class; } diff --git a/src/gen_stub.php b/src/gen_stub.php index 66cb054b..30fb1f7a 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -4866,7 +4866,9 @@ function parseFunctionLike( } if ($param->default instanceof Expr\ClassConstFetch && $param->default->class->toLowerString() === "self") { - throw new Exception('The exact class name must be used instead of "self"'); + $defaultValue = getTranslator()->getClassConstValue($func, $name->className->name, $param->default->name->name); + } else { + $defaultValue = $param->default ? $prettyPrinter->prettyPrintExpr($param->default) : null; } $foundVariadic = $param->variadic; @@ -4877,7 +4879,7 @@ function parseFunctionLike( $param->variadic, $type, isset($docParamTypes[$varName]) ? Type::fromString($docParamTypes[$varName]) : null, - $param->default ? $prettyPrinter->prettyPrintExpr($param->default) : null, + $defaultValue, AttributeInfo::createFromGroups($param->attrGroups) ); if (!$param->default && !$param->variadic) { diff --git a/tests/aot/self-class/002.phpt b/tests/aot/self-class/002.phpt new file mode 100644 index 00000000..ea2e814c --- /dev/null +++ b/tests/aot/self-class/002.phpt @@ -0,0 +1,22 @@ +--TEST-- +self class +--FILE-- +run('null'); +} +?> +--EXPECT-- +string(4) "null" +string(6) "string" \ No newline at end of file