From 7aeda4a43dbe9a7bbc03cd6dac26d8b6472bfdfd Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 17 Jan 2026 18:43:52 +0100 Subject: [PATCH] test remembered types in inherited scopes --- ...remember-readonly-constructor-narrowed.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/PHPStan/Analyser/nsrt/remember-readonly-constructor-narrowed.php b/tests/PHPStan/Analyser/nsrt/remember-readonly-constructor-narrowed.php index 55f8351fad..ab12c2b2cb 100644 --- a/tests/PHPStan/Analyser/nsrt/remember-readonly-constructor-narrowed.php +++ b/tests/PHPStan/Analyser/nsrt/remember-readonly-constructor-narrowed.php @@ -143,3 +143,28 @@ public function doFoo() { assertType('int', $this->prop->writable); } } + +class HelloWorldReadonlyPropertyInClosureScope { + private readonly int $i; + + public function __construct() + { + if (rand(0,1)) { + $this->i = 4; + } else { + $this->i = 10; + } + } + + public function doFoo() { + assertType('4|10', $this->i); + + (function() { + assertType('4|10', $this->i); + })(); + + $func = function() { + assertType('4|10', $this->i); + }; + } +}