@@ -22,16 +22,43 @@ public static function pushByPath(&$holder, $path, $value)
22
22
&& !is_int ($ key )
23
23
&& false === filter_var ($ key , FILTER_VALIDATE_INT )
24
24
) {
25
+ $ key = (string )$ key ;
25
26
$ ref = new \stdClass ();
26
- $ ref = &$ ref ->$ key ;
27
+ $ ref = &$ ref ->{ $ key} ;
27
28
} else {
28
29
$ ref = &$ ref [$ key ];
29
30
}
30
31
}
31
32
$ ref = $ value ;
32
33
}
33
34
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 )
35
62
{
36
63
$ pathItems = explode ('/ ' , $ path );
37
64
if ('# ' === $ pathItems [0 ]) {
@@ -41,14 +68,14 @@ public static function getByPath(&$holder, $path)
41
68
while (null !== $ key = array_shift ($ pathItems )) {
42
69
$ key = urldecode ($ key );
43
70
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 ) ;
47
74
} else {
48
75
throw new Exception ('Key not found: ' . $ key );
49
76
}
50
77
} else {
51
- if (array_key_exists ($ key , $ ref )) {
78
+ if (self :: arrayKeyExists ($ key , $ ref )) {
52
79
$ ref = $ ref [$ key ];
53
80
} else {
54
81
throw new Exception ('Key not found: ' . $ key );
0 commit comments