I am working on a PHP 7 project with PhpStorm 10.0.2.
Whenever I declare a PHPDoc @param
for an function parameter that has type hinting for a scalar type (string
, int
, ...) I get this warning:
Argument type does not match
Here is some sample code that PhpStorm complains about:
class HostConfig
{
/**
* @var string
*/
private $hostname;
/**
* @var string
*/
private $domainname;
/**
* Creates a new instance of hte HostConfig model.
*
* @param string $hostname A host name (e.g. "dev", "int", "feature-xy")
* @param string $domainname A domain name (e.g. "example.com")
*
* @throws \InvalidArgumentException If the given $hostname is empty
* @throws \InvalidArgumentException If the given $domainname is empty
*/
public function __construct(string $hostname, string $domainname)
{
if (strlen(trim($hostname)) === 0) {
throw new \InvalidArgumentException("The host name cannot be empty");
}
if (strlen(trim($domainname)) === 0) {
throw new \InvalidArgumentException("The domain name cannot be empty");
}
$this->hostname = $hostname;
$this->domainname = $domainname;
}
}
And a screenshot of PhpStorm displaying the questionable "Argument type does not match"-hint for in the PHPDoc for an constructor that has two strongly typed string parameters:
Does anybody know if I am doing something wrong or if this is just a bug in PhpStorm?
Your version of PHPStorm was released only 7 days after PHP 7 so its support for the new features of the language (including scalar type hinting) isn't great. You're experiencing an IDE bug. Your issue is probably this one which is fixed with PHPStorm 10.0.3