I created a singleton pattern for PDO, the problem is that when I use it, I have an infinite loop, for example, making this:
$db=Db::fetch_instance();
$product = $db->query(<query>);
I have this error:
Fatal error: Maximum function nesting level of '100' reached, aborting!
My class is this one:
class Db {
//START OF SINGLETON PATTERN
private static $PDOInstance;
public static function fetch_instance() {
try {
if(empty(self::$PDOInstance)){
self::$PDOInstance = new Db();
}
return self::$PDOInstance;
} catch (Exception $e) {
<something>
}
}
private function __construct() {
return new PDO("something");
}
//START OF DECORATOR PATTERN
public function beginTransaction() {
.......
}
public function query($statement) {
return self::$PDOInstance->query($statement);
}
........
Why this loop?, I dont see any loop.