Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Calling Non-Static Method Statically

Calling non-static method statically has been deprecated for a long time.

It should be noted that, inside a class, it is possible to statically call any methods of the same class. This is needed for edge cases such as parent::__construct(), where the constructor is never static.

PHP code

<?php

class x {
	function foo() {
		print __METHOD__;
	}
}

x::foo();

?>

Before

PHP Deprecated:  Non-static method x::foo() should not be called statically

Deprecated: Non-static method x::foo() should not be called statically
x::foo

After

PHP Fatal error:  Uncaught Error: Non-static method x::foo() cannot be called statically

Fatal error: Uncaught Error: Non-static method x::foo() cannot be called statically

PHP version change

This behavior changed in 8.0.

Error Messages

Extension

Analyzer

© 2023-2026, Damien Seguy - Exakat