Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/06/2010, 18:57
henryc33
 
Fecha de Ingreso: abril-2010
Mensajes: 30
Antigüedad: 14 años
Puntos: 0
__get y __set

bueno quisiera saber si alguien me peude explicar muy detalladamente como y para que sirven estos dos metodos: especialmente en estas lineas, es decir q retorna el metodo get o que sentido tiene alli

Código PHP:
25    if(method_exists($this,'get'.$propertyName)){
26        return call_user_func(array($this,'get'.$propertyName)); 
Código PHP:
function  __get($propertyName) {
22    if(!array_key_exists($propertyName$this->propertyTable)){
23        throw new Exception("Invalid Property ".$propertyName."..!");
24    }
25    if(method_exists($this,'get'.$propertyName)){
26        return call_user_func(array($this,'get'.$propertyName));
27    }
28    else{
29        return $this->data[$this->propertyTable[$propertyName]];
30    }
31 
Código PHP:
33 function  __set($propertyName,  $value) {
34     if(!array_key_exists($propertyName$this->propertyTable)){
35       throw new Exception("Invalid Property".$propertyName."..!");
36     }
37     if(method_exists($this,'set'.$propertyName)){
38         return call_user_func(array($this,'set'.$propertyName),$value);
39     }
40     else{
41        //Si el valor de la propiedad ha cambiado realmente
42        //y no esta en la matriz changedProperties
43        //añadirlo
44        if($this->propertyTable[$propertyName]!= $value &&
45                !in_array($propertyName,$this->changedProperties)) {
46            $this->changedProperties[] = $propertyName;
47        }
48        //Establece ahora el nuevo valor
49        $this->data[$this->propertyTable[$propertyName]] = $value;
50     }
51