PHP inheritance and protected member visibility

后端 未结 2 722
死守一世寂寞
死守一世寂寞 2021-02-13 11:28

I\'ve found something that appears to be a strange inheritance issue in PHP.

From the PHP manual:

Members declared protected can be accessed only

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-13 12:05

    You can access those methods because there is a declaration of them as protected in Foo, which is your parent and that gives you permission to access it. If you remove the declaration from the parent and declare the protected method in B you will get a Fatal Error.

    This is reported as a bug in PHP https://bugs.php.net/bug.php?id=50892

提交回复
热议问题