Skip to content
Fragmented Development

Troubleshooting: PHP Extended Classes

This is really just a quick piece of trivia, but can cause tremendous problems if you're not expecting it.

PHP does not, by default, call the parent class' constructor when you create an instance of an extended class.

If you would like to have this happen, you must add a manual call to the parent constructor, like so: parent::__construct();.

This caused some very random issues in some of my layout templates, so hopefully I've saved you the trouble of tracking them down. Enjoy!

Tags: php

Add Your Comment