1 2 3 4 5 6 7 8 9 10 11 12
<?php abstract class Singleton { private static $instances = array(); public static function getInstance() { $class = get_called_class(); if (!isset(self::$instances[$class])) { self::$instances[$class] = new $class; } return self::$instances[$class]; } }