Why do I get a PHPDoc warning in PhpStorm over this code

Matthieu Napoli picture Matthieu Napoli · Mar 22, 2012 · Viewed 8.8k times · Source

I can't understand why PhpStorm gives me the following warning PHPDoc comment does not match function or method signature over this method:

/**
 * Create a new instance of the class
 * @param string $classname Class to instantiate
 * @return object the instance
 * @throw FactoryException If the class is not instantiable
 */
private function newInstance($classname) {
    $reflectionClass = new \ReflectionClass($classname);
    if (! $reflectionClass->isInstantiable()) {
        throw new FactoryException("The class $classname is not instantiable.");
    }
    return new $classname;
}

The warning isn't very specific, I've tried several things like changing the return type to "Object", "mixed" or even "int" (to try) but it didn't change. What is the problem here ?

Answer

MetalFrog picture MetalFrog · Mar 22, 2012

It should be @throws not @throw.

If you just type /** over the line of a function or class var declaration it'll auto insert a base PHPDoc for you. That's how I noticed the difference.

enter image description here