php abstract 抽象类的写法
<?php
abstract class Shape{
abstract protected function get_area();
//和一般方法不同的是,这个方法没有大括号
//不能创建这个抽象类的实例
}
class rectangle extends Shape{
private $width;
private $height;
function __construct($width = 0,$height = 0 ){
$this->width = $width;
$this->height = $height;
}
function get_area(){
echo ($this->width+$this->height)*2;
}
}
$Shape_rect = new rectangle(20,30);
$Shape_rect->get_area();
?>