Skip to content

Add str_split() throw type extension - #6522

Merged
ondrejmirtes merged 1 commit into
2.2.xfrom
str-split-throw-type
Sep 22, 2026
Merged

ondrejmirtes merged 1 commit into
2.2.xfrom
str-split-throw-type

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

PhpStorm stubs now declare @throws \ValueError on str_split(), so every call became an explicit throw point.

str_split() throws ValueError (Argument #2 ($length) must be greater than 0) only when $length is less than 1; the string itself never matters. This is the same on PHP 8.0–8.5, and PHP 7 only warns and returns false.

The extension returns VoidType (no throw point) when:

  • the analysed PHP version is below 8.0,
  • $length is not passed,
  • the native type of $length is a subtype of int<1, max>.

Otherwise it keeps the declared ValueError. That covers str_split($s, 0), a native int $length, and a PHPDoc-only positive-int. A native narrowing like if ($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

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
@ondrejmirtes
ondrejmirtes merged commit 084c97e into 2.2.x Sep 22, 2026
875 of 890 checks passed
@ondrejmirtes
ondrejmirtes deleted the str-split-throw-type branch September 22, 2026 10:22
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.

1 participant