diff --git a/src/gen_stub.php b/src/gen_stub.php index c4cf6529..25774959 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -148,7 +148,7 @@ function processStubFile(string $stubFile, Context $context, bool $includeOnly = return $fileInfo; } catch (Exception $e) { - throw new RuntimeException("In " . getTranslator()->getRelativePath($stubFile) . ": {$e->getMessage()}"); + throw new RuntimeException("In " . getTranslator()->getRelativePath($stubFile) . ": {$e->getMessage()}\n". $e->getTraceAsString()); } } @@ -3246,7 +3246,8 @@ class PropertyInfo extends VariableLike $propertyName = $this->name->getDeclarationName(); - if ($this->defaultValue === null) { + // New 操作作为属性的默认值,需编译器处理 gen_stub 作为 null 值 + if ($this->defaultValue === null || $this->defaultValue instanceof Expr\New_) { $defaultValue = EvaluatedValue::null(); } else { $defaultValue = EvaluatedValue::createFromExpression($this->defaultValue, null, null, $allConstInfos); diff --git a/tests/aot/object_property/prop-005.phpt b/tests/aot/object_property/prop-005.phpt new file mode 100644 index 00000000..2631cf5b --- /dev/null +++ b/tests/aot/object_property/prop-005.phpt @@ -0,0 +1,48 @@ +--TEST-- +Property with nullable type +--FILE-- +name = $name; + } + function handleError() { + echo $this->name . "\n"; + } +} +class SpaRenderer { function render() { echo "SpaRenderer\n"; } } + +class App { + public function __construct( + private Router $router, + private SessionManager $sessions = new SessionManager(), + private CsrfGuard $csrf = new CsrfGuard(), + private Handler $errors = new Handler('Handler'), + private SpaRenderer $spa = new SpaRenderer(), + ) {} + + public function run() { + $this->router->dispatch(); + $this->sessions->start(); + $this->csrf->validate(); + $this->errors->handleError(); + $this->spa->render(); + } +} + +function main() +{ + $app = new App(new Router()); + $app->run(); +} +?> +--EXPECT-- +router +SessionManager +CsrfGuard +Handler +SpaRenderer \ No newline at end of file