class A{
const FOO = 1;
}
class B extends A{
const FOO = 5;
function foo(){
print self::FOO;
print static::FOO;
}
}
$b = new B;
$b->foo();
It prints 5 in both cases.
So there’s no difference in using static vs self on constants?
In the context of Late Static Binding there is a difference.
Consider this code:
If you run this code, the output will be:
When referencing
self::FOO, the value of1is printed (even thoughbar()was called on classB, but when thestatickeyword was used, late static binding took effect and it referenced theFOOconstant fromBrather thanAwhen using the static keyword.This is relevant for PHP 5.3 and later.