Constructor Needed

<?php


const A = 'b::c';

class B {
    static function C() { echo __METHOD__; }
}

//valid call to \B::C()
constant('A')();

// class A not found
//new A;

// Call to undefined function A()
A();

// parse error, this is not supported
//{A}();

By default, classes don’t need a constructor, and it may be omitted. It is also true in the case of child classes: PHP look for a local constructor, then a parent constructor, and it is valid to have none of them.

On the other hand, if any of the child makes an explicit call to parent::__construct, then, there must be at least an explicit constructor in the family. Or, PHP generates Cannot call constructor error message.

As a rule of thumb, it might be good to always include the constructor definition, to avoid adding it later, down the road.

See Also

PHP Error Messages

PHP Features

Last updated: 14 July 2026