From 83a05112830cec3c73e6e5a391d146794e5a7a6e Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 27 Jul 2025 20:51:13 +0200 Subject: [PATCH 1/2] Add non regression test --- .../Rules/Functions/CallCallablesRuleTest.php | 5 +++ .../PHPStan/Rules/Functions/data/bug-3616.php | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/PHPStan/Rules/Functions/data/bug-3616.php diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index 837f9faf73..c82080b9ed 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -307,6 +307,11 @@ public function testBug9614(): void $this->analyse([__DIR__ . '/data/bug-9614.php'], []); } + public function testBug3616(): void + { + $this->analyse([__DIR__ . '/data/bug-3616.php'], []); + } + public function testBug10814(): void { $this->analyse([__DIR__ . '/data/bug-10814.php'], [ diff --git a/tests/PHPStan/Rules/Functions/data/bug-3616.php b/tests/PHPStan/Rules/Functions/data/bug-3616.php new file mode 100644 index 0000000000..94a6fd44e0 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-3616.php @@ -0,0 +1,31 @@ + */ + const FACTORIES = [ + 'a' => [Factory::class, 'a'], + 'b' => [Factory::class, 'b'] + ]; + + public function withLiteral(): void + { + (self::FACTORIES['a'])(); + } + + public function withVariable(string $id): void + { + if (!isset(self::FACTORIES[$id])) { + return; + } + + (self::FACTORIES[$id])(); + } +} From b0807a518eca26de01d7f3502a3bc29a0b359843 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 27 Jul 2025 21:28:26 +0200 Subject: [PATCH 2/2] Add test --- .../PHPStan/Rules/Functions/data/bug-3616.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/PHPStan/Rules/Functions/data/bug-3616.php b/tests/PHPStan/Rules/Functions/data/bug-3616.php index 94a6fd44e0..8b3304f3c3 100644 --- a/tests/PHPStan/Rules/Functions/data/bug-3616.php +++ b/tests/PHPStan/Rules/Functions/data/bug-3616.php @@ -29,3 +29,25 @@ public function withVariable(string $id): void (self::FACTORIES[$id])(); } } + +class HelloWorld2 +{ + const FACTORIES = [ + 'a' => [Factory::class, 'a'], + 'b' => [Factory::class, 'b'] + ]; + + public function withLiteral(): void + { + (self::FACTORIES['a'])(); + } + + public function withVariable(string $id): void + { + if (!isset(self::FACTORIES[$id])) { + return; + } + + (self::FACTORIES[$id])(); + } +}