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

前端 未结 2 1129
忘掉有多难
忘掉有多难 2021-02-09 14:37

Consider the code below:

name;
              


        
2条回答
  •  清歌不尽
    2021-02-09 14:44

    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).

提交回复
热议问题