PHP

PHP

Made by DeepSource

Unused private class property found PHP-W1075

Anti-pattern
Minor
Autofix

The class contains unused private property. These private class properties should be removed as they can sometimes lead to confusion while reading the code.

It is also recommended that you review these unused private properties, in case they were added for later use in the code, but the author missed using them.

Bad practice

class User
{
    // invalid: $name is never unused
    private string $name = 'Hello';

    public function getName(): string
    {
        return 'John';
    }
}

Recommended

Make sure to delete private class properties that are not used:

class User
{
    public function getMessage(): string
    {
        return 'Hello';
    }
}

References