phanalist

E0006: Property Modifiers

In plain English: Properties inside classes must have explicit visibility modifiers (public, protected, or private) and should generally not be left unprotected.

Why it matters: Public properties allow any external code to mutate object state directly, bypassing validation and encapsulation. Explicit property modifiers protect internal state and enforce object-oriented design principles.

❌ The Bad Example

class User {
    // Property without visibility modifier or left public
    string $name;
}

✅ The Good Example

class User {
    private string $name;

    public function getName(): string {
        return $this->name;
    }
}

What the rule checks

When it does not report

How to fix

Configuration

E0006 has no configuration options and is enabled by default.

Junior Engineer’s Rule of Thumb:

Make your class properties private or protected by default, and expose access only through well-defined methods!