可以說,我有這樣的代碼:PHP顯示所有聲明類的名稱?
<?php
class hello {
var $greeting = "hello";
function hello(){
echo $this->greeting;
return;
}
}
$hello1 = new hello;
$hello2 = new hello;
$hello4 = new hello;
?>
我如何得到它的回聲實例化對象的所有名稱(如果可能的話它們各自的類),使它回聲(可能在一個陣列)「hello1 => hello,hello2 => hello,hello4 => hello「。
如果這是不可能的,有沒有什麼辦法從類內部告訴實例的名字,比如echo instance_name($ this);會讓我「你好1」。謝謝。
不想編輯標題,但它有點誤導。只有一個類聲明,class hello。您正在查找此(或任何其他)類的_instances_和引用這些實例的變量。 – VolkerK 2009-05-05 08:17:32