Repository navigation
Add array_chunk() throw type extension - #6524
Merged
Merged
Conversation
PhpStorm stubs now declare @throws \ValueError on array_chunk(), which made every call an explicit throw point. It is thrown only when $length is less than 1, even for an empty array, and PHP 7 only warns. The decision reads the native type of $length, so a PHPDoc-only positive-int keeps the ValueError. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dhb4ssXuKVWcVBcNFpsdn7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PhpStorm stubs now declare
@throws \ValueErroronarray_chunk(), so every call became an explicit throw point.array_chunk()throwsValueError(Argument #2 ($length) must be greater than 0) only when$lengthis less than 1. This happens even for an empty array. It is the same on PHP 8.0–8.5, and PHP 7 only warns.The extension returns
VoidTypewhen the analysed PHP version is below 8.0, or when the native type of$lengthis a subtype ofint<1, max>. Otherwise it keeps theValueError. That coversarray_chunk($a, 0), a nativeint $length, and a PHPDoc-onlypositive-int. A native narrowing likeif ($length > 0)removes it.Tests are in
CatchWithUnthrownExceptionRuleTest, with separate expectations for PHP 8.0+ and for PHP < 8.0, where every catch is dead. Both fail without the extension; the < 8.0 expectations were verified locally on PHP 7.4.The PRs for
array_chunk(),get_class(),hash(),array_fill()andunserialize()are all based on 2.2.x. They add their test methods at different places inCatchWithUnthrownExceptionRuleTest, so they merge cleanly in any order (checked).🤖 Generated with Claude Code
https://claude.ai/code/session_01Dhb4ssXuKVWcVBcNFpsdn7