Changeset View
Changeset View
Standalone View
Standalone View
src/docs/flavor/php_pitfalls.diviner
Show First 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | |||||
You can cast a dictionary into an object. | You can cast a dictionary into an object. | ||||
```lang=php | ```lang=php | ||||
$obj = (object)array('flavor' => 'coconut'); | $obj = (object)array('flavor' => 'coconut'); | ||||
echo $obj->flavor; // Outputs 'coconut'. | echo $obj->flavor; // Outputs 'coconut'. | ||||
echo get_class($obj); // Outputs 'stdClass'. | echo get_class($obj); // Outputs 'stdClass'. | ||||
``` | ``` | ||||
This is occasionally useful, mostly to force an object to become a Javascript | This is occasionally useful, mostly to force an object to become a JavaScript | ||||
dictionary (vs a list) when passed to `json_encode()`. | dictionary (vs a list) when passed to `json_encode()`. | ||||
= Invoking `new` With an Argument Vector is Really Hard = | = Invoking `new` With an Argument Vector is Really Hard = | ||||
If you have some `$class_name` and some `$argv` of constructor arguments | If you have some `$class_name` and some `$argv` of constructor arguments | ||||
and you want to do this: | and you want to do this: | ||||
```lang=php | ```lang=php | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0