YII2 abstract class BaseActiveRecord, implements the interface ActiveRecordInterface, and its find () method is not overloaded!

Source: Internet
Author: User
The file path of the BaseActiveRecord class is: Project vendoryiisoftyii2dbBaseActiveRecord. php does not need to implement all methods in the interface because the BaseActiveRecord class is abstract, or does the find () method in the interface not need to be implemented if it is? Or the file path of the yii2. .. BaseActiveRecord class is: Project \ vendor \ yiisoft \ yii2 \ db \ BaseActiveRecord. php
Is it because the BaseActiveRecord class is abstract that it does not need to implement all the methods in the interface, or does it not need to be implemented if the find () method in the interface is static? Or is yii2 processed elsewhere?

Reply content:

The file path of the BaseActiveRecord class is: Project \ vendor \ yiisoft \ yii2 \ db \ BaseActiveRecord. php
Is it because the BaseActiveRecord class is abstract that it does not need to implement all the methods in the interface, or does it not need to be implemented if the find () method in the interface is static? Or is yii2 processed elsewhere?

I tested php5.5.11 and found that abstract classes do not need to implement methods in interfaces, but they must implement all methods in interfaces in inheritance classes.
BaseActiveRecord inherits some methods of the model, and the remaining methods are implemented in the inheritance class 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();

Normal output dd

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.