diff --git a/src/Utils/Utils.php b/src/Utils/Utils.php index 73b7a9f04..cbffe2588 100644 --- a/src/Utils/Utils.php +++ b/src/Utils/Utils.php @@ -268,10 +268,16 @@ public static function suggestionList(string $input, array $options): array */ public static function extractKey($objectLikeValue, string $key) { - if (is_array($objectLikeValue) || $objectLikeValue instanceof \ArrayAccess) { + if (is_array($objectLikeValue)) { return $objectLikeValue[$key] ?? null; } + if ($objectLikeValue instanceof \ArrayAccess) { + return $objectLikeValue[$key] + ?? $objectLikeValue->{$key} // @phpstan-ignore-line Variable property access on ArrayAccess is fine here, we do the same for arbitrary objects + ?? null; + } + if (is_object($objectLikeValue)) { return $objectLikeValue->{$key} ?? null; } diff --git a/tests/Executor/ExecutorTest.php b/tests/Executor/ExecutorTest.php index 812c33d4a..ee3bf6b88 100644 --- a/tests/Executor/ExecutorTest.php +++ b/tests/Executor/ExecutorTest.php @@ -1190,6 +1190,7 @@ public function testDefaultResolverGrabsValuesOffOfCommonPhpDataStructures(): vo 'name' => 'ArrayAccess', 'fields' => [ 'set' => Type::int(), + 'setProperty' => Type::int(), 'unsetNull' => Type::int(), 'unsetThrow' => Type::int(), ], @@ -1224,6 +1225,8 @@ public function testDefaultResolverGrabsValuesOffOfCommonPhpDataStructures(): vo 'arrayAccess' => [ 'type' => $ArrayAccess, 'resolve' => static fn (): \ArrayAccess => new class() implements \ArrayAccess { + public ?int $setProperty = 1; + /** @param mixed $offset */ #[\ReturnTypeWillChange] public function offsetExists($offset): bool @@ -1317,6 +1320,7 @@ public function __get(string $name): ?int } arrayAccess { set + setProperty unsetNull unsetThrow } @@ -1344,6 +1348,7 @@ public function __get(string $name): ?int ], 'arrayAccess' => [ 'set' => 1, + 'setProperty' => 1, 'unsetNull' => null, 'unsetThrow' => null, ],