Ver Mensaje Individual
  #28 (permalink)  
Antiguo 08/05/2011, 11:41
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 10 meses
Puntos: 1517
Respuesta: Clave numérica en objeto?

Una idea de lo que puedes hacer de aquí en adelante con tu plugin
Código PHP:
Ver original
  1. <?php
  2. class Property
  3. {
  4.     protected $_data = array();
  5.  
  6.     public function __get($key)
  7.     {
  8.         if(!array_key_exists($key, $this->_data)) {
  9.             throw new OutOfBoundsException();
  10.         }
  11.         return $this->_data[$key];
  12.     }
  13.  
  14.     public function __set($key, $val)
  15.     {
  16.         /**
  17.          * Si no deseas que sobre-escriba los datos
  18.          *
  19.          * if(!array_key_exists($key, $val)){
  20.          *  $this->_data[$key] = $val;
  21.          * }
  22.          */
  23.         $this->_data[$key] = $val;
  24.     }
  25. }
  26.  
  27. class Foo extends Property
  28. {
  29.     public function bar()
  30.     {
  31.         return $this->_data;
  32.     }
  33.  
  34.     public function wpsi_options_page()
  35.     {
  36.         add_options_page(__('WP Smart Image II', 'wp-smart-image'), __('WP Smart Image II', 'wp-smart-image'), 8, 'wp-smart-image-ii', 'wpsi_options');
  37.     }
  38.  
  39.     //...
  40. }
  41.  
  42. $f = new Foo();
  43. $f->{100} = '100';
  44. $f->{200} = '200';
  45. $f->{300} = '300';
  46. $f->{300} = 'trecientos'; //sobre-escribe el anterior
  47.  
  48. echo $f->{100} . PHP_EOL;
  49. echo $f->{200} . PHP_EOL;
  50. echo $f->{300} . PHP_EOL;
  51.  
  52. //o
  53. print_r($f->bar());
  54.  
  55. add_action('admin_menu', array($f, 'wpsi_options_page'));
  56. //...
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos