scusate,
come faccio a creare una variabile esterna a una classe con referenza al numero oggetto creato?
esempio:
Codice PHP:
class Test {
var $name, $b;
function test( $name, $b ){
$this->name = $name;
$this->b = $b;
}
}
se io ho un loop che crea degli oggetti test
Codice PHP:
while( $e = mysql_fetch_row( $ris ) ) {
$testObj[] = new Test( $e[1], $e[2] );
}
in pratica io vorrei, una volta creati gli oggetti
$testObj[0] { 'test1', 0 }
$testObj[1] { 'ciao', 2 }
$testObj[2] { 'comestai', 5 }
$testObj[3] { 'bene', 66 }
avere una referenza esterna in un array in modo tale che richiamando
$referenzeObj['comestai']
ritorni la chiave 2.
(ovviamente, il parametro name è unico)
(e ovviamente facendo unset( $referenzeObj['comestai'] ); deve cancellarsi anche $testObj[2] )
qualcuno può aiutarmi?