PHP Strict Standards: Declaration of should be compatible

前端 未结 4 1318
Happy的楠姐
Happy的楠姐 2021-02-19 12:47

I have the following hierarchy of classes:

class O_Base {...}

class O extends O_Base {...}

abstract class A_Abstract {
    public function save(O_Base $obj) {         


        
4条回答
  •  北荒
    北荒 (楼主)
    2021-02-19 13:52

    Change A_Abstract to

    abstract class A_Abstract {
        public function save(O $obj) {...}
    }
    

    No matter that O is extended from O_Base, they are two different objects, and as A extends A_Abstract the save functions need to be compatible with each other, meaning you need to pass the same object in, O.

提交回复
热议问题