phanalist

E0003: Method Modifiers

In plain English: Methods inside classes should always have an explicit visibility modifier (public, protected, or private) rather than relying on legacy default visibility.

Why it matters: Leaving methods without explicit modifiers creates ambiguity about whether a method is intended to be part of the public API or internal helper logic. Explicit visibility enforces proper encapsulation and class design.

❌ The Bad Example

class Calculator {
    // Missing visibility modifier
    function add(int $a, int $b): int {
        return $a + $b;
    }
}

✅ The Good Example

class Calculator {
    public function add(int $a, int $b): int {
        return $a + $b;
    }
}

What the rule checks

When it does not report

How to fix

Configuration

E0003 has no configuration options and is enabled by default.

Junior Engineer’s Rule of Thumb:

Always explicitly declare public, protected, or private on every method you write.