Ver Mensaje Individual
  #18 (permalink)  
Antiguo 09/05/2010, 20:29
atrianaster
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: PHP 5.2 vs PHP 5.3 parámetros por defecto

maturano:

Nunca afirme que no se podía. En cuanto a tu código buen aporte, veo que estuviste haciendo la tarea en casa. Estoy convencido y no hay más peros.

El código quedaría así:

Código PHP:
Ver original
  1. <?php
  2. /**
  3.  * Represents a connection between PHP and a database server
  4.  *
  5.  */
  6. final class Database extends PDO
  7. {
  8.     static private  $dns = DNS;
  9.     static private  $username = USERNAME;
  10.     static private  $passwd = PASSWD;
  11.     static private  $options;
  12.     static private  $instance;
  13.     static private  $constructIsPrivate = true;
  14.  
  15.     /**
  16.      * A private constructor; prevents direct creation of object
  17.      *
  18.      * @access static private
  19.      */
  20.     public function __construct()
  21.     {
  22.       if (self::$constructIsPrivate) {
  23.          trigger_error('Call to private ' . __CLASS__ . '::__construct() from invalid context', E_USER_ERROR);
  24.       }
  25.       try {
  26.            parent::__construct(self::$dns, self::$username, self::$passwd/*, self::$options*/);
  27.            $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  28.       } catch (PDOException $e) {
  29.            echo 'Connection failed: ' . $e->getMessage();
  30.       }
  31.     }
  32.  
  33.     /**
  34.      * Create a instance of Database class with The singleton method
  35.      *
  36.      * @access static public
  37.      * @return Database object
  38.      */
  39.      static public function getInstance()
  40.      {
  41.        if (!isset(self::$instance))
  42.        {
  43.          self::$constructIsPrivate = false;
  44.          $c = __CLASS__;
  45.          self::$instance = new $c;
  46.          self::$constructIsPrivate = true;
  47.        }
  48.         return self::$instance;
  49.      }
  50.  
  51.     /**
  52.      * Executes an SQL statement, returning a result set as a PDOStatement object
  53.      *
  54.      * @access public
  55.      * @param  string $statement
  56.      * @param  $PDO
  57.      * @param  object $object
  58.      * @return PDOStatement
  59.      */
  60.      public function query($statement, $PDO, $object)
  61.      {
  62.         return parent::query($statement, $PDO, $object);
  63.      }
  64.  
  65.  
  66.     /**
  67.      * Prevent users to clone the instance
  68.      *
  69.      * @access public
  70.      * @return string trigger_error
  71.      */
  72.     public function __clone()
  73.     {
  74.         trigger_error('Clone is not allowed.', E_USER_ERROR);
  75.     }
  76. }
  77. ?>