Abstract Constants¶
By WebSmithery
<?php
abstract class Foo {
// self-referential 'abstract' declaration
const NAME = self::NAME;
}
class Fooling extends Foo {
// Overrides definition from parent class
// Without this declaration, an error will be triggered
const NAME = 'Donald';
}
There’s a pretty common pattern to declare “abstract class constants” in PHP.
PHP lazy loading will prevent the error “Fatal error: Uncaught Error: Cannot declare self-referencing constant self::NAME” if the constant is overloaded.
This makes an effective ‘abstract constant’, that must be defined to be usable.
See Also¶
PHP Features¶
Last updated: 14 July 2026