From 563e438f7fcee064ab8fccb96d4516db84d4256e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 13 Nov 2022 20:30:10 +0100 Subject: [PATCH] parse_str() might return arrays by-ref --- stubs/core.stub | 14 +++++++------- .../NonexistentOffsetInArrayDimFetchRuleTest.php | 11 +++++++++++ tests/PHPStan/Rules/Arrays/data/bug-8356.php | 9 +++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 tests/PHPStan/Rules/Arrays/data/bug-8356.php diff --git a/stubs/core.stub b/stubs/core.stub index 01d26d6dd17..588abf28909 100644 --- a/stubs/core.stub +++ b/stubs/core.stub @@ -70,10 +70,16 @@ function bin2hex(string $string): string {} /** * @param array $result - * @param-out array> $result + * @param-out array|array> $result */ function parse_str(string $string, array &$result): void {} +/** + * @param array $result + * @param-out array|array> $result + */ +function mb_parse_str(string $string, array &$result = []): bool {} + /** @param-out float $percent */ function similar_text(string $string1, string $string2, float &$percent = null) : int {} @@ -300,12 +306,6 @@ function fsockopen(string $hostname, int $port = -1, int &$error_code = null, st */ function headers_sent(string &$filename = null, int &$line = null): bool {} -/** - * @param mixed $result - * @param-out array> $result - */ -function mb_parse_str(string $string, &$result = []): bool {} - /** * @param-out callable-string $callable_name */ diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index 6a12a4a920a..1447c6c9f68 100644 --- a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php @@ -700,4 +700,15 @@ public function testBug6243(): void $this->analyse([__DIR__ . '/data/bug-6243.php'], []); } + public function testBug8356(): void + { + $this->bleedingEdge = true; + $this->analyse([__DIR__ . '/data/bug-8356.php'], [ + [ + "Offset 'x' might not exist on array|string.", + 7, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Arrays/data/bug-8356.php b/tests/PHPStan/Rules/Arrays/data/bug-8356.php new file mode 100644 index 00000000000..192a71d3630 --- /dev/null +++ b/tests/PHPStan/Rules/Arrays/data/bug-8356.php @@ -0,0 +1,9 @@ +