I have a base class in PHP Hack with a function:
// This method is used to return just one Apple Type
protected static function Apple(): AppleType {
return AppleType;
}
Now I have two types of classes - one using a base trait, one doesn't.
The trait has the below function:
// This method is used to return more than one Apple Type
protected static function Apples(): keyset[AppleType] {
return keyset[AppleType];
}
The child classes which don't use this trait can override the base class Apple() method. But the classes which do use the trait, must override Apples() and not Apple().
Now I want to provide an invariant exception:
Something like:
invariant(Apple() is not overridden in this class, 'Class must override Apples() and not Apple()');
i.e. invariant to provide enforcement that a class using trait must not be able to override base class's Apple() and throws exception during runtime.
Please help me in writing this invariant. I tried many things, but somehow it doesn't work right.