Common causes
- Legacy code written for PHP 5/7 that called instance methods statically
- A method that uses $this called as ClassName::method()
- WordPress hooks registered as 'MyClass::method' or array('MyClass', 'method') for non-static methods
- Confusing Laravel facades with the underlying class (calling a class directly instead of its facade)
- A library update that changed a static helper into an instance method
How to fix it
- Look at the method definition. Open the class and check whether the method uses $this or object state. That decides whether it should be static.
- Call it on an instance. If it uses $this, create or inject an object: $formatter = new Formatter(); $formatter->price($x); or use constructor injection in frameworks.
- Make it static if it is stateless. If the method does not touch $this, declare it public static function price(...) and keep the Class::method() calls.
- Fix WordPress hook callbacks. Use [$this, 'method'] or [new MyClass(), 'method'] for instance methods; 'MyClass::method' only works for static methods.
- Use the facade in Laravel. Static-looking calls like Cache::get() work through facades. Import Illuminate\Support\Facades\Cache, not the underlying Repository class.
- Update legacy plugins. If the call is inside an old plugin or theme, update it or find a PHP 8 compatible replacement.
PHP
class Formatter
{
public static function price(float $v): string // stateless: static
{
return number_format($v, 2);
}
}
// WordPress, instance method:
add_action('init', [$this, 'register']); How to stop it happening again
- Declare stateless helpers as static explicitly
- Prefer dependency injection over static calls for services
- Test legacy code on PHP 8 before upgrading