Unfinished Class Doesn’t Compile¶
By Jan Nedbal
<?php
// this is FATAL ERROR
class A extends B {}
class B extends C {}
class C {}
PHP is not able to use a class before it is defined. Yet, when the second class is simple enough to be entirely defined, it would. When the class is not completely defined, aka it has the extends, implements, or use (for trait) keywords, PHP postpone the finalization of the class to execution phase, and consider it as non-defined.
See Also¶
PHP Error Messages¶
PHP Features¶
Last updated: 14 July 2026