Symfony v2.8 Response( $message ) method 'returning' more than expected Symfony v2.8 Response( $message ) method 'returning' more than expected ajax ajax

Symfony v2.8 Response( $message ) method 'returning' more than expected


It's not a very clear error message but it sounds like your error is coming from Xdebug, and not PHP.

You can see a similar issue here.

I would check your "Watches" tab in the PHPStorm debug tab, and also from PHPStorm go to Run > View Breakpoints and remove all of them. To be sure you could also deactivate XDebug temporarily (via php.ini settings) to confirm that the problem disappears.


Try returning a new JsonResponse($json) instead of new Response($json).

As in:

use Symfony\Component\HttpFoundation\JsonResponse;// ...return new JsonResponse(['message' => $message]);

If you really (and I mean really) want to return a Response for whatever reason, you can also do:

$response = new Response(json_encode(['message' => $message]);$response->headers->set('Content-Type', 'application/json');return $response;

Bear in mind that I have never tried the last alternative, because JsonResponse has always worked for me. Also, JsonResponse extends Response class, so if you need anything from Response class, you can get it in JsonResponse.

The last response example is attached to this answer because of this Symfony Documentation.