Foros del Web » Programando para Internet » PHP »

PHP OO Falta argunmento

Estas en el tema de Falta argunmento en el foro de PHP en Foros del Web. Bueno habia terminado de escribir este tema, pero retrocedi sin querer y se borro todo. Bueno tengo el problema con unos warning que me aparece. ...
  #1 (permalink)  
Antiguo 02/11/2012, 07:39
 
Fecha de Ingreso: mayo-2012
Ubicación: Valparaiso
Mensajes: 30
Antigüedad: 12 años
Puntos: 0
Exclamación Falta argunmento

Bueno habia terminado de escribir este tema, pero retrocedi sin querer y se borro todo.

Bueno tengo el problema con unos warning que me aparece.

Warning: Missing argument 1 for Persona::getRut(), called in C:\xampp\htdocs\POO\index.php on line 30 and defined in C:\xampp\htdocs\POO\persona.php on line 18
RUT : 17474396-7
Warning: Missing argument 1 for Persona::getNombre(), called in C:\xampp\htdocs\POO\index.php on line 31 and defined in C:\xampp\htdocs\POO\persona.php on line 24


NOMBRE: felipe

Como pueden ver me devuelven los valores, pero con unos molestos warning y no he podido solucionarlo.

dejo mi codigo

index.php
Código PHP:
Ver original
  1. <?php
  2. require_once('persona.php');
  3. $sw = 0;
  4. if($_POST){
  5.     $rut = strtolower(stripslashes($_POST["rut"]));
  6.     $nombre= strtolower(stripslashes($_POST["nombre"]));
  7.     $sw = 1;
  8.     $persona = new Persona($rut,$nombre);
  9. }
  10.  
  11.  
  12. ?>
  13. <!DOCTYPE html>
  14. <head></head>
  15. <html>
  16. <body>
  17.     <form action="" method="post">
  18.         <label>Rut:</label>
  19.         <input type="text" name="rut"><br>
  20.         <label>Nombre:</label>
  21.         <input type="text" name="nombre">
  22.         <input type="submit" value="ir">
  23.     </form>
  24.     <br>
  25.     <br>
  26.     <?php
  27.     if($sw==1){
  28.         echo "RUT : ".$persona->getRut();
  29.         echo "<br><br> NOMBRE: ".$persona->getNombre();
  30.     }
  31.     ?>
  32. </body>
  33. </html>

persona.php
Código PHP:
Ver original
  1. <?php
  2.     //Persona.php
  3.    
  4.     class Persona{
  5.    
  6.         var $rut;
  7.         var $nombre;
  8.        
  9.         function __construct($rut,$nombre){
  10.             $this->rut     = $rut;
  11.             $this->nombre  = $nombre;
  12.         }
  13.        
  14.         //getter y setter
  15.         function setRut($rut) {
  16.             $this->rut = $rut;
  17.         }
  18.         function getRut($rut) {
  19.             return $this->rut;
  20.         }
  21.         function setNombre($nombre) {
  22.             $this->nombre = $nombre;
  23.         }
  24.         function getNombre($nombre) {
  25.             return $this->nombre;
  26.         }
  27.        
  28.     }
  29. ?>

solo tengo los getter y setter, aun no entiendo porque me pide un parametro. Si me pueden ayudar, seria genial, gracias
  #2 (permalink)  
Antiguo 02/11/2012, 07:54
 
Fecha de Ingreso: noviembre-2010
Mensajes: 62
Antigüedad: 13 años, 5 meses
Puntos: 11
Respuesta: Falta argunmento

Los errores estan porque no estas definiendo bien las variables, es "$rut" y no "rut", como es "$nombre" y no "nombre", aca te dejo el codigo correcto:

Código PHP:
function getRut($rut) {
            return 
$this->$rut;
        }

function 
getNombre($nombre) {
            return 
$this->$nombre;
        } 
  #3 (permalink)  
Antiguo 02/11/2012, 08:07
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: Falta argunmento

el mismo warning te lo dice

Cita:
function getRut() {
return $this->rut;
}

.....

function getNombre() {
return $this->nombre;
}
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}
  #4 (permalink)  
Antiguo 02/11/2012, 22:13
 
Fecha de Ingreso: mayo-2012
Ubicación: Valparaiso
Mensajes: 30
Antigüedad: 12 años
Puntos: 0
Respuesta: Falta argunmento

Cita:
Iniciado por grassofabian Ver Mensaje
Los errores estan porque no estas definiendo bien las variables, es "$rut" y no "rut", como es "$nombre" y no "nombre", aca te dejo el codigo correcto:

Código PHP:
function getRut($rut) {
            return 
$this->$rut;
        }

function 
getNombre($nombre) {
            return 
$this->$nombre;
        } 
Gracias amigo por contestar, lamentablemente tienes la respuesta incorrecta.
el codigo quedaria asi:

Código PHP:
Ver original
  1. function getRut() {
  2.             return $this->rut;
  3.         }
  4.  
  5.         function getNombre() {
  6.             return $this->nombre;
  7.         }  
  8.  
  9. [B]Quite el parametro en los get y funciono todo de maravilla sin warning[/B]
  #5 (permalink)  
Antiguo 02/11/2012, 22:14
 
Fecha de Ingreso: mayo-2012
Ubicación: Valparaiso
Mensajes: 30
Antigüedad: 12 años
Puntos: 0
Respuesta: Falta argunmento

Cita:
Iniciado por IsaBelM Ver Mensaje
el mismo warning te lo dice
Gracias amigo, habia encontrado la respuesta pero no tuve tiempo de probarla, revise el foro ... y tenia lo mismo, te pasaste, saludos.

Etiquetas: warning
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:26.