Internal Static Call¶
<?php
class a {
function foo() {
echo __METHOD__ . PHP_EOL;
}
}
class b extends a {}
class c extends b {
function bar() {
$this::foo();
$this->foo();
a::foo();
b::foo();
c::foo();
d::foo();
static::foo();
self::foo();
parent::foo();
}
}
class d extends c {}
(new c)->bar();
Trap of the day: one of the calls in bar() generates a ‘Non-static method a::foo() cannot be called statically’ error.
Which one? It is the d::foo(). All other calls are made within the C class : internal calls may use static or normal syntax, while external calls must use the correct call syntax. This allows calls like ‘parent::__construct()’.
When the call to bar() is made with ‘(new d)’, the ‘d::foo()’ works again.
See Also¶
PHP Error Messages¶
PHP Features¶
Last updated: 14 July 2026