首页 > YII2抽象类BaseActiveRecord,实现接口ActiveRecordInterface,其find()方法没有重载!

YII2抽象类BaseActiveRecord,实现接口ActiveRecordInterface,其find()方法没有重载!

BaseActiveRecord类的文件路径为:项目\vendor\yiisoft\yii2\db\BaseActiveRecord.php
是因为BaseActiveRecord类为abstract才不需要实现接口中的全部方法,还是接口中的find()方法为static就不需要实现?还是yii2中再别的地方做了处理?


php5.5.11测试了一下,发现abstract类不需要实现Interface中的方法,但是要在继承类中实现Interface中的所有方法。
BaseActiveRecord继承了model的部分方法,剩下的方法在继承类ActiveRecord中实现了。

ActiveRecordInterface.php

phpinterface ActiveRecordInterface{
    public static function a();
    public function b();
    public function c();
}

BaseActiveRecord.php

phpinclude "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

phpinclude "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

【热门文章】
【热门文章】