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.
class UserService {
// Missing return type signature
public function getUser($id) {
return $this->repository->find($id);
}
}
class UserService {
// Explicit return type signature
public function getUser(int $id): ?User {
return $this->repository->find($id);
}
}
: void, : mixed, or union types).E0008 has no configuration options and is enabled by default.
Always specify parameter types and return types on your methods. It turns your code into living documentation!