Why is it possible to override instance variables in PHP but not in Java?

淺唱寂寞╮ 提交于 2019-12-03 07:44:35

No, it has nothing to do with weak typing.

I guess this was simply a design decision that the PHP developers took. It may be because it is more of a scripting language than Java. (In Java, you would need to have a "virtual" lookup table for fields to support this or, alternatively, automatically generated getters / setters).

You made the instance variable protected, this means extending classes can overwrite it. If you want to prevent that use private.

http://www.php.net/manual/en/language.oop5.visibility.php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!