When inferring a type, the default parameter value (type) is lost when the parameter is typehinted
Opened this issue · 0 comments
romalytvynenko commented
Hello, Roman,
I encountered a similar problem with rendering the response body as a string. However, there seems to be something mystical going on.
I use: v0.11.27
Code to Reproduce:
final class ApiResponse
{
public static function json(
mixed $data = [],
string $message = null,
$status = Response::HTTP_OK
): JsonResponse {
$success = match (true) {
$status >= 200 && $status < 300 => true,
default => false,
};
return new JsonResponse([
'success' => $success,
'message' => $message,
'data' => $data,
], $status);
}
}
Observed Behavior
-
Without a type declaration for the $status argument, the code works as expected and produces the correct json response body.
-
Issue: When I add a type declaration (int) to the $status argument, the response body is rendered as a string.
Originally posted by @tegos in #540 (comment)