Repository navigation
Add unserialize() throw type extension - #6528
Merged
Merged
Conversation
PhpStorm stubs now declare @throws \TypeError and \ValueError on unserialize(), which made every call an explicit throw point. Both are thrown for invalid $options, which a call without them or with a constant valid array cannot have, and PHP 7 only warns. TypeError is also thrown when the data does not fit a typed property, so it stays unless no class is allowed: then objects become __PHP_Incomplete_Class. The decisions read native types. 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 \TypeErrorand@throws \ValueErroronunserialize(), so every call became an explicit throw point.On PHP 8.0+,
unserialize()throws:TypeError/ValueErrorfor invalid$options:allowed_classesthat is notarray|bool;allowed_classesentry that is not a valid class name (8.4+);max_depththat is not anint, or is negative.TypeErrorwhen the data does not fit a typed property (Cannot assign string to property R::$x of type int), whatever the options.PHP 7 only warns.
The extension decides on native types:
$options, or with a constant options array that is valid:TypeErroronly.allowed_classesis absent, a bool, or a list of constant class-name strings; andmax_depthis absent orint<0, max>.allowed_classesset tofalseor[]:VoidType. Objects then become__PHP_Incomplete_Class, so no typed property can reject the data (checked on PHP 8.5).TypeError|ValueError.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