Ver Mensaje Individual
  #5 (permalink)  
Antiguo 18/01/2016, 15:00
x_atrix
 
Fecha de Ingreso: enero-2016
Mensajes: 71
Antigüedad: 8 años, 3 meses
Puntos: 14
Respuesta: Patron singleton

Aquí lo llevas...
Código PHP:
<?php 
/** 
 * Singleton class 
 */ 
class Singleton 
    
/** 
     * The instance of this class 
     * @var object 
     */ 
    
private static $instance null

    
/** 
     * Returns only one instance of this class 
     * @return object 
     */ 
    
public static function instance() { 
        if (!
self::$instance instanceof self
            
self::$instance = new self(); 

        return 
self::$instance
    } 

    
/** 
     * Private constructor 
     */ 
    
private function __construct() { 

    } 

    
/** 
     * No serialization allowed 
     */ 
    
public function __sleep() { 
        
trigger_error("No serialization allowed!"E_USER_ERROR); 
    } 

    
/** 
     * No cloning allowed 
     */ 
    
public function __clone() { 
        
trigger_error("No cloning allowed!"E_USER_ERROR); 
    }
}