JSON objects in PHP

PHP is easy. You don’t have to know type of variable, before you use it. But sometimes it’s very problematic especially when we are dealing with JSON.

Here is an example:


It’s a very odd combination of arrays and objects. To build this type of object we have to typecast some of variables:

  $builder = [
            'page-size' => 50,
            'channel' => 'buy',
            'sort'  => (object)[],
            'filters' => (object)['surrounding-suburbs' => true],
            'localities' => [(object)['subdivision' => 'DO', 'locality' => 'Unknown']]