Repository navigation
Report unset() of an offset on a union with a scalar member - #6724
Open
SanderMuller wants to merge 1 commit into
Open
SanderMuller wants to merge 1 commit into
SanderMuller wants to merge 1 commit into
Conversation
unset($x['k']) deprecates when $x is false and throws an Error when $x is true, an int, a float or a string. UnsetRule reported this only when the offset can never be accessed, so array|false, array|int and array|string went unreported. Report a union with a scalar member as well, with reportMaybes, the way NonexistentOffsetInArrayDimFetchRule reports offset reads. A type whose offset access is not even legal (an object without ArrayAccess) is left to NonexistentOffsetInArrayDimFetchRule, which already reports it inside unset(). mixed is not reported, because it is only maybe a scalar. Gated behind the unsetOffsetOnMaybeAccessible bleeding edge toggle. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
SanderMuller
force-pushed
the
unset-rule-maybe-offset
branch
from
October 9, 2026 22:53
b93e3a0 to
125e411
Compare
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.
unset($x['k'])deprecates when$xisfalse(since PHP 8.1) and throws anErrorwhen$xistrue, anint, afloator astring.UnsetRulereported this only when the offset can never be accessed, so a union likearray|false,array|intorarray|stringwent unreported:This PR reports a union with a scalar member as well:
reportMaybes, so from level 7, the same asNonexistentOffsetInArrayDimFetchRulereports offset reads.unsetOffsetOnMaybeAccessible.mixedis not reported, because it is only maybe a scalar. The test covers ajson_decode()result afterisset().ArrayAccess) is left out.NonexistentOffsetInArrayDimFetchRulealready reports it insideunset(), so it would be reported twice.array|nullis not reported, becauseunset()onnulldoes nothing.The first version of this PR used
RuleLevelHelper::findTypeToCheck(), and mutation testing showed that its union filter callback could not be tested here. Checking for a scalar member is simpler, and it also coversarray|string.On WordPress trunk from 2026-10-07 at level 8, the toggle adds one error:
unset( $redirect['port'] )on aparse_url()result inredirect_canonical().The
shopware/shopwareintegration job reports one new error, and I think it is correct.ImportExportProfileApiTest.php:85does$entry = current(...), which isarray|false, and thenunset($entry[$property]). Shopware enables bleeding edge, so the check runs there. It needs an entry inshopware-baseline.neonin phpstan/phpstan.This is the follow-up I mentioned in #6722, which keeps the type of the variable after such an
unset(). The two PRs do not depend on each other.🤖 Generated with Claude Code