The SQLite3 object has not been correctly initialised or is already closed

Description

There was an attempt to use the Sqlite3 database, while it is not yet initialised, or already closed.

When extending the Sqlite3 class, make sure the constructor calls the parent constructor, so that Sqlite3 is actually initiliazed.

Note that the Sqlite3 object was not unset yet, so it still exists. It would have been another error then.

Example

<?php

// Not yet initialized object
$sqlite3 = new class (':memory:') extends Sqlite3 {
    function __construct() {}
};
$sqlite3->query('SELECT 1'); // OK

// already closed object
$sqlite3 = new Sqlite3(':memory:');
$sqlite3->query('SELECT 1'); // OK
$sqlite3->close();
$sqlite3->query('SELECT 1'); // Not OK

?>

Solutions

  • Check that the parent class of an extended Sqlite3 class is actually called.

  • Check that the parent class was not already destroyed.

  • Check that whole object is destroyed, not just the parent class.

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>`_.