有人可以解釋爲什麼父類析構函數被調用兩次嗎?我的印象是,一個子類只能使用調用父的析構函數:父:: __自毀()php析構函數被調用兩次
class test {
public $test1 = "this is a test of a pulic property";
private $test2 = "this is a test of a private property";
protected $test3 = "this is a test of a protected property";
const hello = 900000;
function __construct($h){
//echo 'this is the constructor test '.$h;
}
function x($x2){
echo ' this is fn x'.$x2;
}
function y(){
print "this is fn y";
}
function __destruct(){
echo '<br>now calling the destructor<br>';
}
}
class hey extends test {
function hey(){
$this->x('<br>from the host with the most');
echo ' <br>from hey class'.$this->test3;
}
}
$obj = new test("this is an \"arg\" sent to instance of test");
$obj2 = new hey();
echo $obj2::hello;
/*
the result:
this is fn x
from the host with the most
from hey classthis is a test of a protected property900000
now calling the destructor
now calling the destructor
*/
看來你正試圖從測試類 –
$ TEST3被保護在好端端的一個私有變量訪問什麼然後意思是hey類繼承了它 – zero