Reputation: 5395
According to the CakePHP 4 docs
// If you want a json response
$response = $response->withType('application/json')
->withStringBody(json_encode(['Foo' => 'bar']));
If you run phpstan on level 7 it will give this error
Parameter #1
$string
of methodCake\Http\Response::withStringBody()
expectsstring|null
,string|false
given.
json_encode
is a core PHP function which has return types string|false
so can't be modified.
withStringBody()
is a CakePHP core method which accepts string|null
.
How can you get around that error since neither of those 2 things can be modified directly?
Upvotes: 1
Views: 40