Answers
php5.5.11测试了一下,发现abstract类不需要实现Interface中的方法,但是要在继承类中实现Interface中的所有方法。
BaseActiveRecord继承了model的部分方法,剩下的方法在继承类ActiveRecord中实现了。
ActiveRecordInterface.php
php
interface ActiveRecordInterface{ public static function a(); public function b(); public function c(); }
BaseActiveRecord.php
php
include "ActiveRecordInterface.php"; abstract class BaseActiveRecord implements ActiveRecordInterface{ // public static function a(){echo 'a';} // public function b(){echo 'b';} // public function c(){echo 'c';} }
test.php
php
include "BaseActiveRecord.php"; class test extends BaseActiveRecord{ public static function a(){} public function b(){} public function c(){} function d(){ echo 'dd'; } } $a = new test(); $a->d();
正常输出dd
中二病无法好转
answered 11 years, 7 months ago