State::jsonSerialize()

Returns the data to be serialized as JSON.

Table of Contents
  1. Description
  2. Example

Description

State::jsonSerialize(): mixed;

This method is a requirement to be able to implement the JsonSerializable interface and aims to make the data convertable to JSON. You won’t use this method directly, the json_encode() function will call this method automatically.

Example

$state = new State([1, 2, 'a', ['b' => true]]);

echo json_encode($state); // Returns `[1,2,"a",{"b":true}]`

State::jsonSerialize()

Returns the data to be serialized as JSON.