background image

self::

$instance

 = 

new

 

$c

;

}

return

 self::

$instance

;

public

 

function

 pub_function() {

echo

 "you request public function<br>";

echo

 

$this

->

public

;

}

protected

 

function

 pro_function(){

echo

 "you request protected function<br>";

echo

 

$this

->

protected

;

}

private

 

function

 pri_function(){

echo

 "you request private function<br>";

echo

 

$this

->

private

;

}
}

class

 test1 

extends

 test{

public

 

function

 __construct(){

parent::tank();
parent::__construct();
}

public

 

function

 tank(){

echo

 

$this

->

public

;

echo

 

$this

->

private

//Notice: Undefined property: test1::$private

echo

 

$this

->

protected

;

$this

->pub_function();

$this

->pro_function();

$this

->pri_function(); 

//Fatal error: Call to private method test::pri_function() from context 'test1'

}

public

 

function

 pro_extends_function(){

echo

 "you request extends_protected function<br>";

}

public

 

function

 pri_extends_function(){

echo

 "you request extends_private function<br>";

}
}

error_reporting

(E_ALL);

$test

 = 

new

 test1();

$test

 -> tank(); 

//子类和父类有相同名字的属性和方法,实例化子类时,子类的中的属性和

方法会盖掉父类的。