You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
1.8 KiB

<?php
//继承父类中的publc成员demo
class classParent
{
public function __construct()
{
echo '--进入父类--'.'<br>';
}
public function demo() //public 成员
{
echo '--父类 方法--'.'<br>';
}
public function __destruct()
{
echo '--推出父类--'.'<br>';
}
}
class son extends classParent
{
public function __construct()
{
echo '--进入子类--'.'<br>';
}
public function __destruct()
{
echo '--退出子类--'.'<br>';
}
}
// $obj = new son();
// $obj -> demo();
/*继承父类中的保存成员*/
class parent2
{
public function __construct()
{
echo '--进入父类--'.'<br>';
}
protected function demo()
{
echo '父类保护成员'.'<br>';
}
public function __destruct()
{
echo '--退出父类--'.'<br>';
}
}
class son2 extends parent2{
public function __construct()
{
echo '--进入子类--'.'<br>';
}
public function test()
{
echo '子类公共成员'.'<br>';
$this -> demo(); //这个this是指子son2;
}
public function __destruct()
{
echo '--退出子类--'.'<br>';
}
}
// $obj = new son2();
// $obj -> test();
/*继承父类中的私有成员*/
class parent3{
private function func(){
echo '父类私有成员'.'<br>';
}
}
class son3 extends parent3{
public function test(){
$this -> func(); //会报错
}
}
$obj=new son3();
$obj -> test();
?>