phanalist

E0008: Return Type Signature

In plain English: Methods should declare explicit return type signatures (e.g., : int, : string, : void, : ?User).

Why it matters: Without return type signatures, other developers (and static analysis tools) have to read through the entire method body to figure out what it returns. Type declarations make code self-documenting and let PHP catch type mismatches at runtime.

❌ The Bad Example

class UserService {
    // Missing return type signature
    public function getUser($id) {
        return $this->repository->find($id);
    }
}

✅ The Good Example

class UserService {
    // Explicit return type signature
    public function getUser(int $id): ?User {
        return $this->repository->find($id);
    }
}

What the rule checks

When it does not report

How to fix

Configuration

E0008 has no configuration options and is enabled by default.

Junior Engineer’s Rule of Thumb:

Always specify parameter types and return types on your methods. It turns your code into living documentation!