Yes in PHP there are no "forward declarations", as in C ++. Therefore class Color; not valid in PHP.
Now why do you get "Class 'Color' not found." ? The problem is that this line
class ColorRGBA extends Color
runs before this line:
class Color {
So Color really undefined. To solve this problem, you can do the following:
class Color{ public static function isValid(&$tokens, $i) { include_once 'ColorRGBA.php'; include_once 'ColorHSLA.php'; return ColorRGBA::isValid($tokens, $i) || ColorHSLA::isValid($tokens, $i); } }
This works because the Color class is now fully defined, and the ColorRGBA / ColorHSLA defined only when isValid called.
You can also put include_once after defining the Color class.
source share