<?php
// Crear variable $Ryan y asignarle como valor la clase Usuario
$Ryan = new Usuario();
// Ahora la variable Ryan es una clase, con variables $nombre y $edad
$Ryan->AsignarNombre("Ryan");
$Ryan->AsignarEdad(19);
// Crear variable $Ismael y asignarle como valor la clase Usuario
$Ismael = new Usuario();
// Ahora la variable Ismael es una clase, con variables $nombre y $edad
$Ismael->AsignarNombre("Ismael");
$Ryan->AsignarEdad(21);
// Mostrar informacion de ryan
$Ryan->MostrarDatos();
// Mostrar informacion de Ismael
$Ismael->MostrarDatos();
Class Usuario{
public $nombre;
public $edad;
function AsignarNombre($nombre){
$this->nombre = $nombre;
}
function AsignarEdad($edad){
$this->edad = $edad;
}
function MostrarDatos(){
echo $this->nombre.' tiene '.$this->$edad.'\n';
}
}
?>
Warning: Undefined variable $edad in /in/IEnGQ on line 37
Warning: Undefined property: Usuario::$ in /in/IEnGQ on line 37
Ryan tiene \n
Warning: Undefined variable $edad in /in/IEnGQ on line 37
Warning: Undefined property: Usuario::$ in /in/IEnGQ on line 37
Ismael tiene \n
Notice: Undefined variable: edad in /in/IEnGQ on line 37
Notice: Undefined property: Usuario::$ in /in/IEnGQ on line 37
Ryan tiene \n
Notice: Undefined variable: edad in /in/IEnGQ on line 37
Notice: Undefined property: Usuario::$ in /in/IEnGQ on line 37
Ismael tiene \n
Output for 7.3.32 - 7.3.33
Ryan tiene \nIsmael tiene \n
Output for 7.0.0 - 7.0.20
Notice: Undefined variable: edad in /in/IEnGQ on line 37
Fatal error: Uncaught Error: Cannot access empty property in /in/IEnGQ:37
Stack trace:
#0 /in/IEnGQ(18): Usuario->MostrarDatos()
#1 {main}
thrown in /in/IEnGQ on line 37
Process exited with code 255.
Notice: Undefined variable: edad in /in/IEnGQ on line 37
Fatal error: Cannot access empty property in /in/IEnGQ on line 37
Process exited with code 255.
Output for 5.0.4
Notice: Undefined variable: edad in /in/IEnGQ on line 37
Notice: Undefined property: Usuario::$ in /in/IEnGQ on line 37
Ryan tiene \n
Notice: Undefined variable: edad in /in/IEnGQ on line 37
Notice: Undefined property: Usuario::$ in /in/IEnGQ on line 37
Ismael tiene \n
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: edad in /in/IEnGQ on line 37
Notice: Undefined property: Usuario::$ in /in/IEnGQ on line 37
Ryan tiene \n
Notice: Undefined variable: edad in /in/IEnGQ on line 37
Notice: Undefined property: Usuario::$ in /in/IEnGQ on line 37
Ismael tiene \n
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/IEnGQ on line 25
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/IEnGQ on line 25
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/IEnGQ on line 25
Process exited with code 255.