File tree Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -52,8 +52,9 @@ $http->fetch("http://example.com/api/something.json")
52
52
. count($json->results)
53
53
. PHP_EOL;
54
54
55
+ // Notice that type-safe getters are available on all Json objects:
55
56
echo "Name of first result: "
56
- . $json->results[0]->name
57
+ . $json->results[0]->getString(" name")
57
58
. PHP_EOL;
58
59
});
59
60
Original file line number Diff line number Diff line change 26
26
echo "PHP.Gt repository list: " . PHP_EOL ;
27
27
28
28
foreach ($ json as $ repo ) {
29
- echo $ repo ->name . PHP_EOL ;
29
+ echo $ repo ->getString ( " name " ) . PHP_EOL ;
30
30
}
31
31
});
32
32
Original file line number Diff line number Diff line change @@ -66,10 +66,18 @@ public function offsetUnset($offset):void {
66
66
throw new ImmutableObjectModificationException ();
67
67
}
68
68
69
- /** @link https://php.net/manual/en/iterator.current.php */
69
+ /**
70
+ * @return int|float|bool|string|null|Json
71
+ * @link https://php.net/manual/en/iterator.current.php
72
+ */
70
73
public function current () {
71
74
if (is_array ($ this ->jsonObject )) {
72
- return $ this ->jsonObject [$ this ->iteratorKey ];
75
+ $ obj = $ this ->jsonObject [$ this ->iteratorKey ];
76
+ if ($ obj instanceof StdClass) {
77
+ return new self ($ obj );
78
+ }
79
+
80
+ return $ obj ;
73
81
}
74
82
75
83
$ property = $ this ->iteratorPropertyNames [$ this ->iteratorKey ];
You can’t perform that action at this time.
0 commit comments