From c6d4e3278c78cd7f5c3029f5493ffa5c1eef791e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 8 Sep 2025 11:15:53 +0200 Subject: [PATCH] Added regression test --- .../InvalidKeyInArrayDimFetchRuleTest.php | 10 ++++++++++ tests/PHPStan/Rules/Arrays/data/bug-12273.php | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/PHPStan/Rules/Arrays/data/bug-12273.php diff --git a/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayDimFetchRuleTest.php index c6e3df9768..22716afcd4 100644 --- a/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayDimFetchRuleTest.php @@ -106,4 +106,14 @@ public function testBug13135(): void ]); } + public function testBug12273(): void + { + $this->analyse([__DIR__ . '/data/bug-12273.php'], [ + [ + 'Possibly invalid array key type mixed.', + 16, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Arrays/data/bug-12273.php b/tests/PHPStan/Rules/Arrays/data/bug-12273.php new file mode 100644 index 0000000000..6989899dcc --- /dev/null +++ b/tests/PHPStan/Rules/Arrays/data/bug-12273.php @@ -0,0 +1,17 @@ + \DateTime::class, + 'stdclass' => \stdClass::class, + ]; + + $settings = json_decode('{"class": "datetim"}'); + + \PHPStan\dumpType($map); + \PHPStan\dumpType($settings->class); + + new ($map[$settings->class])(); +}