php static延迟静态绑定

<?php
abstract class Coffee{
private $cups;
function __construct(){
$this->cups=static::getCups();
}

public static function create(){
return new static();
}
static function getCups(){
return "default";
}
}

//print_r(Coffee::create());
class 临江仙 extends Coffee{
static function getCups(){
return "来三大杯";
}
}
print_r(临江仙::create());

//抽象类只能继承,不能实例化和静态访问 :)
?>

你可能感兴趣的:(PHP,面向对象)