@@ -22,16 +22,43 @@ public static function pushByPath(&$holder, $path, $value)
2222 && !is_int ($ key )
2323 && false === filter_var ($ key , FILTER_VALIDATE_INT )
2424 ) {
25+ $ key = (string )$ key ;
2526 $ ref = new \stdClass ();
26- $ ref = &$ ref ->$ key ;
27+ $ ref = &$ ref ->{ $ key} ;
2728 } else {
2829 $ ref = &$ ref [$ key ];
2930 }
3031 }
3132 $ ref = $ value ;
3233 }
3334
34- public static function getByPath (&$ holder , $ path )
35+ private static function arrayKeyExists ($ key , array $ a )
36+ {
37+ if (array_key_exists ($ key , $ a )) {
38+ return true ;
39+ }
40+ $ key = (string )$ key ;
41+ foreach ($ a as $ k => $ v ) {
42+ if ((string )$ k === $ key ) {
43+ return true ;
44+ }
45+ }
46+ return false ;
47+ }
48+
49+ private static function arrayGet ($ key , array $ a )
50+ {
51+ $ key = (string )$ key ;
52+ foreach ($ a as $ k => $ v ) {
53+ if ((string )$ k === $ key ) {
54+ return $ v ;
55+ }
56+ }
57+ return false ;
58+ }
59+
60+
61+ public static function getByPath ($ holder , $ path )
3562 {
3663 $ pathItems = explode ('/ ' , $ path );
3764 if ('# ' === $ pathItems [0 ]) {
@@ -41,14 +68,14 @@ public static function getByPath(&$holder, $path)
4168 while (null !== $ key = array_shift ($ pathItems )) {
4269 $ key = urldecode ($ key );
4370 if ($ ref instanceof \stdClass) {
44- $ vars = get_object_vars ( $ ref) ;
45- if (array_key_exists ($ key , $ vars )) {
46- $ ref = $ vars [ $ key] ;
71+ $ vars = ( array ) $ ref ;
72+ if (self :: arrayKeyExists ($ key , $ vars )) {
73+ $ ref = self :: arrayGet ( $ key, $ vars ) ;
4774 } else {
4875 throw new Exception ('Key not found: ' . $ key );
4976 }
5077 } else {
51- if (array_key_exists ($ key , $ ref )) {
78+ if (self :: arrayKeyExists ($ key , $ ref )) {
5279 $ ref = $ ref [$ key ];
5380 } else {
5481 throw new Exception ('Key not found: ' . $ key );
0 commit comments