문제

정적 VAR을 포함하는 기본 클래스가있는 경우, 나는이 정적 var를 설정 한 다음 기본 클래스를 확장하는 클래스를 가지고 있으며, 확장 클래스는 이미 설정 한 정적 var의 값을 유지합니다기본 클래스?

도움이 되었습니까?

해결책

Yes, although they're different variables, the static variables in both classes are in the same reference set.

You can break this reference set though, by using reference assignment (=&) or by redeclaring it in the extended class:

class base {
    public static $var;
}
class extended extends base {}

extended::$var = 8; // base::$var == 8
$t = 6;
extended::$var =& $t; // base::$var == 8; extended::$var == 6

class base {
    public static $var;
}
class extended extends base {
    public static $var;
}

extended::$var = 8; // base::$var == null; extended::$var == 8
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top