Object not initialized

Description

This error appears with intl and spl extensions. It happens when an object was not fully initialized with the extension: it was only extended and the parent constructor was omitted. This leaves the custom object valid, but not finalized from the parent point of view.

This error may also happen when the object keeps being used, after an unset() call, or __destructor call.

Example

<?php

class MyDirectoryIterator extends DirectoryIterator {
    public function __construct() {}
}

$it = new MyDirectoryIterator;
try {
    $it->key();
} catch (Error $e) {
    echo $e->getMessage(), \n;
}

?>

Solutions

  • Call parent::__construct in the custom constructor.

  • Remove any call to the object after destruction.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.