<?php
abstract class AbstractClass{
// 定义必须设定的方法
abstract protected function getValue();
abstract protected function prefixValue($prefix);
// 普通方法的定义
public function printOut(){
print $this -> getValue().'\n';
}
public function starice(){
echo "starice\n";
}
}
//Strict standards: Non-static method AbstractClass::starice() should not be called statically in D:\wamp64\www\Ces\ClassCes.php on line 17
// 非静态的方法调用,能出现结果,但是会报错
// AbstractClass::starice();
class CLASS1 extends AbstractClass{
// 继承抽象类的子方法
public function getValue(){
return "ClassCes true";
}
// Fatal error: Class CLASS1 contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (AbstractClass::prefixValue) in D:\wamp64\www\Ces\ClassCes.php on line 19
// 必须实现抽象类的所有抽象方法
protected function prefixValue($prefix){
$str = '接收成功'.$prefix;
return $str;
}
// Fatal error: Access level to CLASS1::prefixValue() must be protected (as in class AbstractClass) or weaker in D:\wamp64\www\Ces\ClassCes.php on line 26
// 实现抽象类的属性或方法,访问权限不能低于父类,不然将会发生语法错误。
}
// Fatal error: Cannot instantiate abstract class Abs