php static property

后端 未结 4 638
隐瞒了意图╮
隐瞒了意图╮ 2021-01-08 01:11

I have two code snippets (regarding the static keyword) which I expect them to have same output, but actually the outputs are different.

The question is

4条回答
  •  走了就别回头了
    2021-01-08 02:07

    Since the sub2 class does not have var2 it takes the value of the base2 class.So when u assigned a new value using this sub2::$var2 = 2; it changed to new value.

    In first code you have overridden that in your extended class.Both variable have scope inside their respective classes.

提交回复
热议问题