From fbce69cd41e8f337ebc00a52498c1e01f94c1653 Mon Sep 17 00:00:00 2001 From: ryium Date: Fri, 11 Nov 2022 01:47:25 +0900 Subject: [PATCH] fix: Mark array_shift as having side effects - fixes https://github.com/phpstan/phpstan/issues/8084 --- bin/functionMetadata_original.php | 1 + resources/functionMetadata.php | 1 + tests/PHPStan/Analyser/NodeScopeResolverTest.php | 1 + tests/PHPStan/Analyser/data/bug-8084.php | 16 ++++++++++++++++ 4 files changed, 19 insertions(+) create mode 100644 tests/PHPStan/Analyser/data/bug-8084.php diff --git a/bin/functionMetadata_original.php b/bin/functionMetadata_original.php index 618ec3b44f..f6e054a756 100644 --- a/bin/functionMetadata_original.php +++ b/bin/functionMetadata_original.php @@ -36,6 +36,7 @@ 'array_replace' => ['hasSideEffects' => false], 'array_replace_recursive' => ['hasSideEffects' => false], 'array_reverse' => ['hasSideEffects' => false], + 'array_shift' => ['hasSideEffects' => true], 'array_slice' => ['hasSideEffects' => false], 'array_sum' => ['hasSideEffects' => false], 'array_udiff' => ['hasSideEffects' => false], diff --git a/resources/functionMetadata.php b/resources/functionMetadata.php index 4aefe1f0d2..eb1774bf3c 100644 --- a/resources/functionMetadata.php +++ b/resources/functionMetadata.php @@ -702,6 +702,7 @@ 'array_replace_recursive' => ['hasSideEffects' => false], 'array_reverse' => ['hasSideEffects' => false], 'array_search' => ['hasSideEffects' => false], + 'array_shift' => ['hasSideEffects' => true], 'array_slice' => ['hasSideEffects' => false], 'array_sum' => ['hasSideEffects' => false], 'array_udiff' => ['hasSideEffects' => false], diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 43efba4291..c629aed2f7 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -1170,6 +1170,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8635.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8625.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8621.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8084.php'); } /** diff --git a/tests/PHPStan/Analyser/data/bug-8084.php b/tests/PHPStan/Analyser/data/bug-8084.php new file mode 100644 index 0000000000..d21d9a0f18 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-8084.php @@ -0,0 +1,16 @@ +