Non-Static Method Called Statically

Fatal error: Uncaught Error: Non-static method App\Service\UserService::findAll() cannot be called statically

Quick Answer

You are using ClassName::method() syntax on a method that is not declared as static. Either make the method static or create an instance of the class first.

Why This Happens

PHP distinguishes between static and instance methods. Static methods are called with :: and do not have access to $this. Instance methods require an object. In PHP 8.0+, calling a non-static method statically throws a fatal error instead of the previous deprecation notice.

The Problem

class UserService {
    public function findAll(): array {
        return $this->repository->findAll();
    }
}
$users = UserService::findAll(); // Not a static method

The Fix

class UserService {
    public function findAll(): array {
        return $this->repository->findAll();
    }
}
$service = new UserService();
$users = $service->findAll();

Step-by-Step Fix

  1. 1

    Check the method declaration

    Look at the method definition. If it does not have the static keyword, it is an instance method that requires an object.

  2. 2

    Create an instance

    Instantiate the class with new and call the method on the instance using -> instead of ::.

  3. 3

    Make static if appropriate

    If the method does not use $this or instance state, add the static keyword to the method declaration.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free