PHP

PHP

Made by DeepSource

Class property provided with an invalid type PHP-T1004

Bug risk
Minor

The class property has an invalid type specified in the Docblock comment. This would lead to emitting wrong type-hint suggestions.

This can happen because of human errors, such as:

  • The class for the property type doesn't exist or contains a typo.
  • The class for the property type has an invalid namespace.
  • The class for the property type is referenced with the incorrect case.
  • The property has trait as its type. Using class or interface is recommended.

Bad practice

trait Helper
{
}

class Checker
{
    /** @var EmailService */
    public $emailService; // "EmailService" class doesn't exist

    /** @var Helper */
    private $helper; // uses trait "Helper" as type, which is incorrect
}

Recommended

class EmailService
{
}

class Helper
{
}

class Checker
{
    /** @var EmailService */
    public $emailService;

    /** @var Helper */
    private $helper;
}

References