I am trying to implement singleton pattern and i am getting the following error
Fatal error: Access level to Database::__construct() must be public (as in class PDO) in /config/database.php on line 29
<?php
class Database extends PDO
{
private static $instance;
private function __construct()
{
return parent::__construct(
"mysql:host=localhost;dbname=live",
"root",
"root"
);
}
public function getInstance() {
if(self::$instance === null) {
self::$instance = new Database();
}
return self::$instance;
}
public function __clone()
{
die(__CLASS__ . ' class cant be instantiated. Please use the method called getInstance.');
}
}
$mySingleton = Database::getInstance();
var_dump($mySingleton);
?>