<?phpuseJSON\Attributes\JSON;useJSON\Unmarshal;include'../vendor/autoload.php';include'FlightRoute.php';/**
* Class Flight
*/classFlight{#[JSON(field: 'airline')]publicstring$airlineName;#[JSON(field: 'aircraft.type')]publicstring$aircraftType;#[JSON(field: 'route', type: FlightRoute::class)]publicarray$route;}// Create a new flight class$flight=newFlight();// Load our JSON data from file$jsonData=json_decode(file_get_contents('flight.json'),true);// Unmarshal JSONUnmarshal::decode($flight,$jsonData);
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi, I started work on something similar but uses PHP 8 attributes, take a look github.com/mrbenosborne/json-unmar....