File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 20
20
*/
21
21
class RecursiveArrayAccess
22
22
{
23
- public static function get (array | \ ArrayAccess $ array , array $ indices )
23
+ public static function get (mixed $ array , array $ indices )
24
24
{
25
25
foreach ($ indices as $ index ) {
26
- if (\is_array ($ array ) ? !\array_key_exists ($ index , $ array ) : !isset ($ array [$ index ])) {
27
- throw new OutOfBoundsException (sprintf ('The index "%s" does not exist. ' , $ index ));
26
+ // Use array_key_exists() for arrays, isset() otherwise
27
+ if (\is_array ($ array )) {
28
+ if (\array_key_exists ($ index , $ array )) {
29
+ $ array = $ array [$ index ];
30
+ continue ;
31
+ }
32
+ } elseif ($ array instanceof \ArrayAccess) {
33
+ if (isset ($ array [$ index ])) {
34
+ $ array = $ array [$ index ];
35
+ continue ;
36
+ }
28
37
}
29
38
30
- $ array = $ array [ $ index] ;
39
+ throw new OutOfBoundsException ( sprintf ( ' The index "%s" does not exist. ' , $ index)) ;
31
40
}
32
41
33
42
return $ array ;
You can’t perform that action at this time.
0 commit comments