From f49204f37e7f856ed8d70a5f9ee65b92d03fecf3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 25 Jun 2026 06:22:24 +0700 Subject: [PATCH 1/2] [Php70] Skip memoize item by key on IfIssetToCoalescingRector --- .../Fixture/skip_memoize_item_by_key.php.inc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 rules-tests/Php70/Rector/StmtsAwareInterface/IfIssetToCoalescingRector/Fixture/skip_memoize_item_by_key.php.inc diff --git a/rules-tests/Php70/Rector/StmtsAwareInterface/IfIssetToCoalescingRector/Fixture/skip_memoize_item_by_key.php.inc b/rules-tests/Php70/Rector/StmtsAwareInterface/IfIssetToCoalescingRector/Fixture/skip_memoize_item_by_key.php.inc new file mode 100644 index 00000000000..c3e1b473b25 --- /dev/null +++ b/rules-tests/Php70/Rector/StmtsAwareInterface/IfIssetToCoalescingRector/Fixture/skip_memoize_item_by_key.php.inc @@ -0,0 +1,17 @@ +items[$key])) { + return $this->items[$key]; + } + + return $this->items[$key] = 'fallback value'; + } +} From e33aff0a7c1ab624b699f90f72e3b0526860335a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 25 Jun 2026 06:28:13 +0700 Subject: [PATCH 2/2] fix --- .../StmtsAwareInterface/IfIssetToCoalescingRector.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rules/Php70/Rector/StmtsAwareInterface/IfIssetToCoalescingRector.php b/rules/Php70/Rector/StmtsAwareInterface/IfIssetToCoalescingRector.php index 0a1e76a39ee..a2ad3211474 100644 --- a/rules/Php70/Rector/StmtsAwareInterface/IfIssetToCoalescingRector.php +++ b/rules/Php70/Rector/StmtsAwareInterface/IfIssetToCoalescingRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr; +use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp\Coalesce; use PhpParser\Node\Expr\Isset_; use PhpParser\Node\Expr\Ternary; @@ -113,6 +114,11 @@ public function refactor(Node $node): ?Node continue; } + if ($stmt->expr instanceof Assign && + $this->nodeComparator->areNodesEqual($ifOnlyStmt->expr, $stmt->expr->var)) { + continue; + } + unset($node->stmts[$key - 1]); if ($stmt->expr instanceof Ternary) {