Ciao a tutti,
sto cercando di creare una classe che dovrebbe semplicemente incrementare e visualizzare un array.
Tipo così
Codice PHP:
$a = array();
$a[0] = "mela";
$a[1] = "pera";
$a[2] = "banana";
foreach ($a as $obj) print $obj;
Ecco il mio tentativo
Codice PHP:
class Lista {
private $list = '';
public function __constructor() {
$this->list = array();
}
public function add($e) {
$this->list[$this->getLength()] = $e;
}
public function getList() {
return $this->list;
}
public function getLength() {
return count($this->list);
}
}
// Test
$lista= new Lista;
$lista-> add("One");
$lista-> add("Two");
$lista-> add("Three");
var_dump($lista);
Così facendo ottengo un array di lunghezza 1 con dentro solo l'ultima stringa (Three).
Qualcuno può aiutarmi a capire dove sbaglio?