Php type hinting not getting along with interfaces and abstract classes?

后端 未结 3 1520
[愿得一人]
[愿得一人] 2020-12-01 18:08

I think it\'ll be much easier to see the problem in a code example than writing the question in the first place. Here is my php code:



        
3条回答
  •  臣服心动
    2020-12-01 18:37

    Does not compute. We had the same discussion yesterday:
    Can parameter types be specialized in PHP

    All your derived classes must implement the method signatures identically.

    This is something that would ideally be checked at runtime. But in PHP the parser does. (To compensate, PHP does not check private/protected attribute access at parsing time, but let that one rather blow up at runtime.)

    If you want to enforce a more stringent type, I would advise:

     assert( is_a($Object, "AClass") );
    

提交回复
热议问题