Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. JsonResponse.php

function JsonResponse::__construct

Parameters

bool $json If the data is already a JSON string:

Overrides Response::__construct

File

vendor/symfony/http-foundation/JsonResponse.php, line 39

Class

JsonResponse
Response represents an HTTP response in JSON format.

Namespace

Symfony\Component\HttpFoundation

Code

public function __construct(mixed $data = null, int $status = 200, array $headers = [], bool $json = false) {
    parent::__construct('', $status, $headers);
    if ($json && !\is_string($data) && !is_numeric($data) && !$data instanceof \Stringable) {
        throw new \TypeError(\sprintf('"%s": If $json is set to true, argument $data must be a string or object implementing __toString(), "%s" given.', __METHOD__, get_debug_type($data)));
    }
    $data ??= new \ArrayObject();
    $json ? $this->setJson($data) : $this->setData($data);
}
RSS feed
Powered by Drupal