Ver Mensaje Individual
  #5 (permalink)  
Antiguo 12/11/2015, 12:21
Avatar de gonzaherrera77
gonzaherrera77
 
Fecha de Ingreso: noviembre-2015
Mensajes: 60
Antigüedad: 10 años, 10 meses
Puntos: 7
Respuesta: Ejecicio clase Fecha

Cita:
Saludo.
Pues las variables están declaradas como private.
Sí se hace referencia a las otras variables que están
siendo usadas como auxiliares (Por ej dayOk),
sí posteriormente se hará algo con ellas,
lo mejor sería declararlas como privadas y accederlas
por un método.

Finalmente, en la función de validarFecha se podría omitir
recibir los valores por la función, y hacer uso de los atributos de la clase,
pues tanto las variables como esta función son privadas.
(Esto haría que la función leer asignara primero los valores)
Podria ser asi? o no estoy entendiendo vien el concepto.

Código PHP:
<?php
public function leer($day, $month, $year) {
   
$this->day = $day;
   
$this->month = $month;
   
$this->year= $year;

   
$this->validarFecha();
}

public function 
validarFecha() {
   if(
$this->day > 0 && $this->day <=31) {
         
$dayOk = true;
   }
   else {
         
$dayOk = false;
   }
   if(
$this->month > 0 && $this->month <=12) {
         
$monthOk = true;
   }
   else {
         
$monthOk = false;
   }
   if(
$this->year > 0 && $this->year <=12) {
         
$yearOk = true;
   }
   else {
         
$yearOk = false;
   }

   if(!
$dayOk, !$monthOk, !$yearOk) {
      echo 
'Fecha no valida...';

      
$this->day = 1;
      
$this->month = 1;
      
$this->year = 1900;
   }
}
?>
¡Saludos!