Base classes(usually abstact ones) can have methods which can be tuned with overriding constants in child classes. Those contants can also have default values.
example:
abstract class BaseClass{
const NAME = '<default name>';
public function sayHello(){
printf("Hello! My name is %s
", static::NAME);
}
}
// will use default constant value
class SomeClass extends BaseClass{}
// constant value is overridden
class OtherClass extends BaseClass{
const NAME = 'Stephen Hawking';
}
(new SomeClass())->sayHello(); // Hello! My name is <default name>
(new OtherClass())->sayHello(); // Hello! My name is Stephen Hawking
But if I replace abstact class with trait I get
PHP Fatal error: Traits cannot have constants in /mnt/tmpfs/1.php on line 4
So is it possible to use them in traits?