Trait that implements JsonSerializable interface. Provides array content for JSON encode.
Trait synopsis
trait JsonSerializableTrait
{
use TypeTrait;
// JsonSerializable interface implementation.
/**
* @return mixed Class serialization content
*/
public function jsonSerialize(): mixed;
}
Examples
use Phrity\O\Array\JsonSerializableTrait;
class MyClass implements JsonSerializable
{
use JsonSerializableTrait;
public function __construct(array $input)
{
$this->initialize($input);
}
}
$class = new MyClass([1, 2, 3]);
echo json_encode($class); // => '[1,2,3]'
Requirements
PHP
^8.0