Ver Mensaje Individual
  #4 (permalink)  
Antiguo 19/11/2014, 14:41
Avatar de marlanga
marlanga
 
Fecha de Ingreso: enero-2011
Ubicación: Murcia
Mensajes: 1.024
Antigüedad: 13 años, 3 meses
Puntos: 206
Respuesta: Problema extraño función empty()

¿Lo has probado?
Código PHP:
Ver original
  1. <?php
  2. class P {
  3.   private $data;
  4.  
  5.   public function __construct() {
  6.     $this->data=array(
  7.       'v1' => 1,
  8.       'v2' => 'dos',
  9.       'v3' => false
  10.     );
  11.   }
  12.  
  13.   public function __get($k) {
  14.     return $this->data[$k];
  15.   }
  16.  
  17.   public function __set($k, $v) {
  18.     if (array_key_exists($k, $this->data,)) {
  19.       $this->data[$k] = $v;
  20.     } else {
  21.       trigger_error("Undefined index: {$k}");
  22.     }
  23.   }
  24.  
  25.   public function __isset($k) {
  26.     return isset($this->data[$k]);
  27.   }
  28. }
  29.  
  30. $p = new P();
  31.  
  32. echo empty($p->v1) ? 'Vacio' : 'No Vacio';
  33. ?>

Última edición por marlanga; 19/11/2014 a las 14:47