Skip to content

Handle empty array case via ConstantArrayType::spliceArray() #4140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Jul 21, 2025

This basically acts as recursion guard because a bit later the following piece of code

		if ($offset === null || $length === null) {
			return $this->degradeToGeneralArray()
				->spliceArray($offsetType, $lengthType, $replacementType);
		}

would degrade the empty constant array to the same empty constant array, calling the same method again, which then leads to infinite recursion.
We have that exact same code for sliceArray() as well btw.

Closes phpstan/phpstan#13279

Was introduced in #3952

@ondrejmirtes ondrejmirtes merged commit 5ba5a86 into phpstan:2.1.x Jul 21, 2025
415 of 420 checks passed
@ondrejmirtes
Copy link
Member

Perfect, thank you!

@herndlm herndlm deleted the array-splice-recursion branch July 21, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Infinite recursion on array_splice
2 participants