1

PhpStorm is highlighting $requestType in the following piece of code in red, which I don't understand why. Maybe a bug in PhpStorm? Maybe is just not a good practice to define like that default function values?

class HttpClient
{
    const RequestTypes = [
        'DEFAULT' => 'default',
        'JSON' => 'json'
    ];

    public function makeRequest(
        string $requestType = self::RequestTypes['DEFAULT']
    ): Response {

        // The function

    }
}

The error message is Default value for parameters with string type can only be string or NULL.

Obviously the ['DEFAULT'] value is a string, but still giving an error.

What do you think?

1 Answers1

2

As commented by Nathan, this seems like an existing PhpStorm bug already reported at Wrong evaluation of type. Thanks!

Community
  • 1
  • 1
  • The question may get closed as "invalid" or similar, since your code *is* best practice, it's just the bug in PHP Storm marking it as an error. – Nathan Craike Mar 23 '17 at 05:30
  • I've flagged the question to be closed. Not 100% sure I chose the correct reasons, but… I don't think it's suitable for Stack Overflow now that we've found it in the PHP Storm issue tracker. – Nathan Craike Mar 23 '17 at 05:35