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.