Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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: 10 September 2026