Beispiel #1
0
        $this->nombre = $nombre;
        $this->cpostal = $cpostal;
        $this->fecha = $fecha;
        self::$num_personas++;
    }
    public function getNif()
    {
        return $this->nif;
    }
    public static function get_Num_personas()
    {
        return self::$num_personas;
    }
}
class Estudiante extends Persona
{
    private $id;
    private $grupo;
    function __construct($nif, $nombre, $cpostal, $fecha, $id, $grupo)
    {
        parent::__construct($nif, $nombre, $cpostal, $fecha);
        $this->id = $id;
        $this->grupo = $grupo;
    }
}
// $persona = new Persona("3486769K","PEDRO PEREZ", 35012,19791109);
// $persona = new Persona("3445699G","MARIA PEREZ", 35018,19981024);
$est = new Estudiante("12345769K", "ESTUDIANTE PEREZ", 35012, 19791109, 12, 34);
echo $est->getNif();
echo "Numero de personas creadas : " . Persona::get_Num_personas();
// echo $persona->getNif();
Beispiel #2
0
<?php

include "Persona.php";
$est1 = new Estudiante("3486769K", "PEDRO PEREZ", 35012, 19791109, 17, 34);
$est2 = new Estudiante("3445699G", "MARIA PEREZ", 35018, 19981024, 15, 34);
$est3 = new Estudiante("12345769K", "ESTUDIANTE PEREZ", 35012, 19791109, 12, 34);
echo $est1->get_TotalPasos() . "<br>";
$est1->caminar();
echo $est1->get_TotalPasos() . "<br>";
// $est1-> caminar(3);
echo "Numero de personas creadas : " . Persona::get_Num_personas();
// echo $persona->getNif();
// creamos un asociativo de estudiantes.
$estudiantes = array($est1, $est2, $est3);
$estudiantes2 = array($est1->getNif() => $est1, $est2->getNif() => $est2, $est3->getNif() => $est3);