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

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

Consider the code below:

name;
              


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-02-09 14:52

    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

提交回复
热议问题