Repository navigation
Add str_split() throw type extension - #6522
Merged
Merged
Conversation
PhpStorm stubs now declare @throws \ValueError on str_split(), which made every call an explicit throw point. It is thrown only when $length is less than 1, 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 \ValueErroronstr_split(), so every call became an explicit throw point.str_split()throwsValueError(Argument #2 ($length) must be greater than 0) only when$lengthis less than 1; the string itself never matters. This is the same on PHP 8.0–8.5, and PHP 7 only warns and returnsfalse.The extension returns
VoidType(no throw point) when:$lengthis not passed,$lengthis a subtype ofint<1, max>.Otherwise it keeps the declared
ValueError. That coversstr_split($s, 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.🤖 Generated with Claude Code
https://claude.ai/code/session_01Dhb4ssXuKVWcVBcNFpsdn7