Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/01/2016, 17:52
german_1441
 
Fecha de Ingreso: diciembre-2015
Ubicación: México
Mensajes: 280
Antigüedad: 8 años, 5 meses
Puntos: 20
Patron singleton

Hola amigos, tengo una duda respecto al patrón singleton,

Teniendo una clase:

Código PHP:
Ver original
  1. class MiClase{
  2.    private static $objeto = null;
  3.    
  4.    public function __construct(){  
  5.    }
  6.  
  7.     public static function singleton(){
  8.        if(!isset(self::$objeto)){
  9.             self::$objeto = new self();
  10.        }
  11.        return self::$objeto;      
  12.    }
  13.  
  14. }

Que diferencia hay a :

Código PHP:
Ver original
  1. class MiClase{
  2.    private static $objeto = null;
  3.    
  4.    public function __construct(){  
  5.    }
  6.  
  7.     public static function singleton(){
  8.        if(!isset(self::$objeto)){
  9.            $miClase = __CLASS__;
  10.             self::$objeto = new $miClase;
  11.        }
  12.        return self::$objeto;      
  13.    }
  14.  
  15. }

Saludos!