Skip to content
Permalink
1754a78265
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
25 lines (21 sloc) 542 Bytes
<?php
class DatabaseSingleton
{
private function __construct()
{
//$this->pdo = new PDO(...);
}
public static function instance()
{
static $instance;
if (is_null($instance)) {
$instance = new static;
}
return $instance;
}
}
$databaseSingleton1 = DatabaseSingleton::instance();
$databaseSingleton2 = DatabaseSingleton::instance();
echo "Same class instance? ",
$databaseSingleton1 === $databaseSingleton2 ? 'YES' : 'NO',
PHP_EOL;