Skip to content

[Php85] Skip increment/decrement on ArrayFirstLastRector - #9079

Merged
TomasVotruba merged 1 commit into
rectorphp:mainfrom
odolbeau:fix/array-first-last-skip-increment
Nov 27, 2026
Merged

TomasVotruba merged 1 commit into
rectorphp:mainfrom
odolbeau:fix/array-first-last-skip-increment

Conversation

@odolbeau

Copy link
Copy Markdown
Contributor

ArrayFirstLastRector rewrites an array dim fetch that is incremented or decremented:

-$longest = max($longest, ++$unionsByDepth[array_key_last($unionsByDepth)]);
+$longest = max($longest, ++array_last($unionsByDepth));

which is a fatal error: Can't use function return value in write context.

The rule already skips assignments, assign ops and unset() (#7657, #7843, #7752, #8425); this adds the same skip for ++/-- (pre and post), using the existing IS_INCREMENT_OR_DECREMENT attribute set by ContextNodeVisitor.

Added the skip_increment_decrement.php.inc fixture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TomasVotruba

Copy link
Copy Markdown
Member

Thank you 👍

@TomasVotruba
TomasVotruba merged commit 2dad902 into rectorphp:main Nov 27, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants