From 2d05f43d9d0e0ef8b2bb3203c6e2cd8978b41775 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 23 Feb 2026 18:23:13 +0700 Subject: [PATCH 1/2] [Php71] Handle crash on partial destruct on ListToArrayDestructRector --- .../Fixture/skip_partial_destruct.php.inc | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 rules-tests/Php71/Rector/List_/ListToArrayDestructRector/Fixture/skip_partial_destruct.php.inc diff --git a/rules-tests/Php71/Rector/List_/ListToArrayDestructRector/Fixture/skip_partial_destruct.php.inc b/rules-tests/Php71/Rector/List_/ListToArrayDestructRector/Fixture/skip_partial_destruct.php.inc new file mode 100644 index 00000000000..2a0790987ab --- /dev/null +++ b/rules-tests/Php71/Rector/List_/ListToArrayDestructRector/Fixture/skip_partial_destruct.php.inc @@ -0,0 +1,10 @@ +id); + } +} From d504e5fae1a61edd501f57f982199211439f9ce4 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 23 Feb 2026 18:26:45 +0700 Subject: [PATCH 2/2] fix --- .../List_/ListToArrayDestructRector.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/rules/Php71/Rector/List_/ListToArrayDestructRector.php b/rules/Php71/Rector/List_/ListToArrayDestructRector.php index ce7d469a1a6..00f97b8ab16 100644 --- a/rules/Php71/Rector/List_/ListToArrayDestructRector.php +++ b/rules/Php71/Rector/List_/ListToArrayDestructRector.php @@ -5,6 +5,7 @@ namespace Rector\Php71\Rector\List_; use PhpParser\Node; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\List_; @@ -78,6 +79,11 @@ public function refactor(Node $node): ?Node $list = $node->var; + // all list items must be set + if ($this->hasPartialDestruct($list)) { + return null; + } + $node->var = new Array_($list->items); return $node; } @@ -93,10 +99,8 @@ public function refactor(Node $node): ?Node $list = $node->valueVar; // all list items must be set - foreach ($list->items as $listItem) { - if ($listItem === null) { - return null; - } + if ($this->hasPartialDestruct($list)) { + return null; } $node->valueVar = new Array_($list->items); @@ -104,6 +108,17 @@ public function refactor(Node $node): ?Node return $node; } + private function hasPartialDestruct(List_ $list): bool + { + foreach ($list->items as $listItem) { + if (! $listItem instanceof ArrayItem) { + return true; + } + } + + return false; + } + public function provideMinPhpVersion(): int { return PhpVersionFeature::ARRAY_DESTRUCT;