Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When inferring a type, the default parameter value (type) is lost when the parameter is typehinted #637

Open
romalytvynenko opened this issue Nov 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@romalytvynenko
Copy link
Member

          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.
    image

  • Issue: When I add a type declaration (int) to the $status argument, the response body is rendered as a string.

image

Originally posted by @tegos in #540 (comment)

@romalytvynenko romalytvynenko changed the title Default parameter value (type) is lost when the parameter is typehinted When inferring a type, the default parameter value (type) is lost when the parameter is typehinted Nov 25, 2024
@romalytvynenko romalytvynenko added the bug Something isn't working label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant