File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 77
88
99
10- $ json = new JSON () ;
10+ $ foo = new JSON ;
1111
12- $ json ->test ->one ->two = 's ' ;
1312
14- echo $ json ->getObject ('test ' )->getObject ('one ' )->getObject ('two ' );
13+
14+
15+ echo '<pre> ' ;
16+ print_r ($ foo ->count ());
17+ echo '<pre> ' ;
Original file line number Diff line number Diff line change 11<?php
22namespace SteeinJSON ;
33
4+ use Countable ;
45use JsonSchema \Constraints \Factory ;
56use JsonSchema \SchemaStorage ;
67use JsonSchema \Validator ;
2324 * @copyright 2017 - Steein Inc
2425 * @version PHP 7 >=
2526 */
26- class JSON extends JSONConfig
27+ class JSON extends JSONConfig implements Countable
2728{
2829 /***
2930 * The array to store all the data
@@ -365,4 +366,18 @@ protected function formattedJson($json = false)
365366
366367 return $ result ;
367368 }
369+
370+ /**
371+ * Count elements of an object
372+ *
373+ * @return int
374+ * @throws \ErrorException
375+ */
376+ public function count ()
377+ {
378+ if (!isset ($ this ->storage ))
379+ throw new \ErrorException ("The store did not match " );
380+ else
381+ return \count ((array )$ this ->storage );
382+ }
368383}
You can’t perform that action at this time.
0 commit comments