<?php
trait Singleton
{
private static $instance;
public static function getInstance() {
if (!(self::$instance instanceof self)) {
self::$instance = new self;
}
return self::$instance;
}
}
// PDO
class SingletonPDO extends PDO
{
use Singleton;
}
// SingletonSplFileObject
class SingletonSplFileObject extends SplFileObject
{
use Singleton;
}
1