- json_encode: documentation ( source)
<?php
class JsonResponse
{
const DEFAULT_ENCODING_OPTIONS = 15;
protected $encodingOptions = self::DEFAULT_ENCODING_OPTIONS;
public function __construct($data = null)
{
$data = json_encode($data, $this->encodingOptions);
}
}
class JsonSerializableObject implements \JsonSerializable
{
public function jsonSerialize()
{
throw new \Exception('This error is expected');
}
}
$serializable = new JsonSerializableObject();
new JsonResponse($serializable);