PHP Strict Standards: Declaration of should be compatible

前端 未结 4 1315
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:35

    I had similar problem.

    For me the explanation is much simpler, without cool theories: in PHP the above code is making method overriding. But the idea of such code in my case was method overloading which is not possible in PHP in this way.

    So, to create required logic (required by your application) you need to use workarounds in order to make compatible method signatures (by inheriting parameters types or making some parameters optional).

提交回复
热议问题