Object of type %s has not been correctly initialized by calling parent::__construct() in its constructor

Description

PHP needs an explicit call to the parent constructor to init the parent class. Sometimes, overwritten constructor is an expected features. With PHP native classes, Datetime and Datetimezone must be explicitely called when extended.

Note that this error is only raised when the object is used, and not at instantiation time.

Example

<?php

class X extends DateTime {
     public function __construct() { }
}

$object = new X;
var_dump(object->format("d"));
?>

Literal Examples

  • Object of type X has not been correctly initialized by calling parent::__construct() in its constructor

Solutions

  • Add a call to the parent __construct() method.