From d1c38c783de130760b078be246eee4eb8bc3fd20 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 12 Dec 2025 19:13:56 +0700 Subject: [PATCH 1/2] [Php85] Skip under unset() on ArrayFirstLastRector --- .../Fixture/skip_under_unset.php.inc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 rules-tests/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector/Fixture/skip_under_unset.php.inc diff --git a/rules-tests/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector/Fixture/skip_under_unset.php.inc b/rules-tests/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector/Fixture/skip_under_unset.php.inc new file mode 100644 index 00000000000..e6e23429a2c --- /dev/null +++ b/rules-tests/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector/Fixture/skip_under_unset.php.inc @@ -0,0 +1,14 @@ + Date: Fri, 12 Dec 2025 19:15:05 +0700 Subject: [PATCH 2/2] fix --- rules/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rules/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector.php b/rules/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector.php index ff4114a440d..0a9e21f563c 100644 --- a/rules/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector.php +++ b/rules/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\FuncCall; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PHPStan\ScopeFetcher; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; @@ -88,6 +89,10 @@ public function refactor(Node $node): ?FuncCall return null; } + if ($node->getAttribute(AttributeKey::IS_UNSET_VAR)) { + return null; + } + $functionName = $this->isName($node->dim, self::ARRAY_KEY_FIRST) ? 'array_first' : 'array_last';