@@ -233,6 +233,47 @@ public static function getValue(
233
233
return self ::getRootValue ($ array , $ key , $ default );
234
234
}
235
235
236
+ /**
237
+ * @param mixed $array Array or object to extract value from, otherwise method will return $default.
238
+ * @param float|int|string $key Key name of the array element, object property name or object method like `getValue()`.
239
+ * @param mixed $default The default value to be returned if the specified array key does not exist. Not used when
240
+ * getting value from an object.
241
+ *
242
+ * @return mixed The value of the element if found, default value otherwise.
243
+ */
244
+ private static function getRootValue (mixed $ array , float |int |string $ key , mixed $ default ): mixed
245
+ {
246
+ if (is_array ($ array )) {
247
+ $ key = self ::normalizeArrayKey ($ key );
248
+ return array_key_exists ($ key , $ array ) ? $ array [$ key ] : $ default ;
249
+ }
250
+
251
+ if (is_object ($ array )) {
252
+ $ key = (string ) $ key ;
253
+
254
+ if (str_ends_with ($ key , '() ' )) {
255
+ $ method = substr ($ key , 0 , -2 );
256
+ /** @psalm-suppress MixedMethodCall */
257
+ return $ array ->$ method ();
258
+ }
259
+
260
+ try {
261
+ /** @psalm-suppress MixedPropertyFetch */
262
+ return $ array ::$ $ key ;
263
+ } catch (Throwable ) {
264
+ /**
265
+ * This is expected to fail if the property does not exist, or __get() is not implemented.
266
+ * It is not reliably possible to check whether a property is accessible beforehand.
267
+ *
268
+ * @psalm-suppress MixedPropertyFetch
269
+ */
270
+ return $ array ->$ key ;
271
+ }
272
+ }
273
+
274
+ return $ default ;
275
+ }
276
+
236
277
/**
237
278
* Retrieves the value of an array element or object property with the given key or property name.
238
279
* If the key does not exist in the array or object, the default value will be returned instead.
@@ -1555,45 +1596,4 @@ private static function parseMixedPath(array|float|int|string $path, string $del
1555
1596
}
1556
1597
return $ newPath ;
1557
1598
}
1558
-
1559
- /**
1560
- * @param mixed $array Array or object to extract value from, otherwise method will return $default.
1561
- * @param float|int|string $key Key name of the array element, object property name or object method like `getValue()`.
1562
- * @param mixed $default The default value to be returned if the specified array key does not exist. Not used when
1563
- * getting value from an object.
1564
- *
1565
- * @return mixed The value of the element if found, default value otherwise.
1566
- */
1567
- private static function getRootValue (mixed $ array , float |int |string $ key , mixed $ default ): mixed
1568
- {
1569
- if (is_array ($ array )) {
1570
- $ key = self ::normalizeArrayKey ($ key );
1571
- return array_key_exists ($ key , $ array ) ? $ array [$ key ] : $ default ;
1572
- }
1573
-
1574
- if (is_object ($ array )) {
1575
- $ key = (string ) $ key ;
1576
-
1577
- if (str_ends_with ($ key , '() ' )) {
1578
- $ method = substr ($ key , 0 , -2 );
1579
- /** @psalm-suppress MixedMethodCall */
1580
- return $ array ->$ method ();
1581
- }
1582
-
1583
- try {
1584
- /** @psalm-suppress MixedPropertyFetch */
1585
- return $ array ::$ $ key ;
1586
- } catch (Throwable ) {
1587
- /**
1588
- * This is expected to fail if the property does not exist, or __get() is not implemented.
1589
- * It is not reliably possible to check whether a property is accessible beforehand.
1590
- *
1591
- * @psalm-suppress MixedPropertyFetch
1592
- */
1593
- return $ array ->$ key ;
1594
- }
1595
- }
1596
-
1597
- return $ default ;
1598
- }
1599
1599
}
0 commit comments