Non Static Method Called Statically¶
It is not possible to call a non-static method statically, and now, it is also not possible to call non-statically a static method.
The static syntax is still valid with expression like parent::__construct. Be aware that a call such as self::foo also checks if the target method is static.
PHP code¶
<?php
class Foo {
public function bar() {}
static function foo() {
self::bar();
}
}
//Non-static method Foo::bar() cannot be called statically (line 10)
Foo::bar();
//Non-static method Foo::bar() cannot be called statically (line 6)
Foo::foo();
?>
Before¶
PHP Deprecated: Non-static method Foo::bar() should not be called statically
Deprecated: Non-static method Foo::bar() should not be called statically
After¶
PHP Fatal error: Uncaught Error: Non-static method Foo::bar() cannot be called statically
Fatal error: Uncaught Error: Non-static method Foo::bar() cannot be called statically
PHP version change¶
This behavior was deprecated in 7.0
This behavior changed in 8.0