From ce818b977127e1c793224d61219cbe6c791f8afa Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 11 Jul 2025 00:53:30 +0200 Subject: [PATCH] Fix fwrite --- resources/functionMap_php74delta.php | 1 + .../StrictComparisonOfDifferentTypesRuleTest.php | 5 +++++ tests/PHPStan/Rules/Comparison/data/bug-13208.php | 14 ++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/PHPStan/Rules/Comparison/data/bug-13208.php diff --git a/resources/functionMap_php74delta.php b/resources/functionMap_php74delta.php index bb05fe2b6a..9b187510c8 100644 --- a/resources/functionMap_php74delta.php +++ b/resources/functionMap_php74delta.php @@ -51,6 +51,7 @@ 'ReflectionProperty::isInitialized' => ['bool', 'object='=>'?object'], 'ReflectionReference::fromArrayElement' => ['?ReflectionReference', 'array'=>'array', 'key'=>'int|string'], 'ReflectionReference::getId' => ['string'], + 'SplFileObject::fwrite' => ['int|false', 'str'=>'string', 'length='=>'int'], 'SQLite3Stmt::getSQL' => ['string', 'expanded='=>'bool'], 'strip_tags' => ['string', 'str'=>'string', 'allowable_tags='=>'string|array'], 'WeakReference::create' => ['WeakReference', 'referent'=>'object'], diff --git a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php index 5e31f50619..3e75e3bc52 100644 --- a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php @@ -996,4 +996,9 @@ public function testBug12946(): void $this->analyse([__DIR__ . '/data/bug-12946.php'], []); } + public function testBug13208(): void + { + $this->analyse([__DIR__ . '/data/bug-13208.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-13208.php b/tests/PHPStan/Rules/Comparison/data/bug-13208.php new file mode 100644 index 0000000000..c46cc7619f --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-13208.php @@ -0,0 +1,14 @@ +fwrite('a') === false) { + throw new \Exception("write failed !"); + } + } +}