PHP: Difference between revisions
adds feature documentation about magic methods |
add note about JSON |
||
| Line 6: | Line 6: | ||
== Language Features == | == Language Features == | ||
=== Magic Methods === | |||
* [https://github.com/guidovanbiemen/setngeti SetnGeti] - an implementation of Magic Methods for getting and setting based on traits and DocBlock comments. | * [https://github.com/guidovanbiemen/setngeti SetnGeti] - an implementation of Magic Methods for getting and setting based on traits and DocBlock comments. | ||
* [https://cspray.github.io/2012/05/13/stop-calling-them-getters-setters Don't do it the wrong way] | * [https://cspray.github.io/2012/05/13/stop-calling-them-getters-setters Don't do it the wrong way] | ||
=== JSON === | |||
With <code>[https://php.net/manual/en/function.json-decode.php json_decode()]</code>, you either get an object, or using the optional second | |||
parameter, you can force the return value to an array. In the former case, you access the content using object notation. In the latter case, you use array notation. | |||
ie. | |||
<source lang="php"> | |||
$data = json_decode($data); | |||
$version = $data->query->general->generator; | |||
// or | |||
$data = json_decode($data, true); | |||
$version = $data['query']['general']['generator']; | |||
</source> | |||
[[Category:PHP]] | [[Category:PHP]] | ||