PHP抽象类和PHP接口
1.抽象类
<?php
abstract class a{
public $name;
public function __construct($name){
$this -> name = $name;
}
public function af(){
echo $this -> name;
}
abstract public function aff();
}
class b extends a{
public function aff(){
echo $this -> name;
}
}
$a = new b('欧阳');
$a -> af();
echo '<br>';
$a = aff();
2.接口类
<?php
abstract class P{
protected $name;
protected function __construct($name='peter'){
$this->name;
}
public function getName(){
return $this->name;
}
abstract protected function setName($value);
}
class stu extends P{
public function __construct($name = 'peter'){
parent::__construct($name);
}
public function setName($value){
$this->value;
}
}
$stu = new stu('猪');
echo '真的很贵哦:' . $stu->getName() . '<hr>';
$stu->setName('灭绝师太');
echo '讲师' . $stu->getName();