Skip to content

[Php70] Skip memoize item by key on IfIssetToCoalescingRector#8083

Merged
TomasVotruba merged 2 commits into
mainfrom
skip-memoize
Jun 25, 2026
Merged

[Php70] Skip memoize item by key on IfIssetToCoalescingRector#8083
TomasVotruba merged 2 commits into
mainfrom
skip-memoize

Conversation

@samsonasik

@samsonasik samsonasik commented Jun 24, 2026

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9784
Ref https://getrector.com/demo/17f33148-a662-4998-b212-d8a5ed25b305

The transformed code become hard to read can possibly cause changed behaviour due to no parentheses on complex use.

-        if (isset($this->items[$key])) {
-            return $this->items[$key];
-        }
-
-        return $this->items[$key] = 'default';
+        return $this->items[$key] ?? $this->items[$key] = 'default';

so I think it should be skipped.

@samsonasik samsonasik requested a review from TomasVotruba June 24, 2026 23:32
@samsonasik

Copy link
Copy Markdown
Member Author

@TomasVotruba ready 👍

@TomasVotruba

Copy link
Copy Markdown
Member

Indeed, I don't get what it does from briefly looking at it.

Thanks, nice improvement 👍

@TomasVotruba TomasVotruba merged commit 0815da7 into main Jun 25, 2026
67 checks passed
@TomasVotruba TomasVotruba deleted the skip-memoize branch June 25, 2026 08:43
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.

Incorrect behavior of IfIssetToCoalescingRector on memoize items by key

2 participants