質問

静的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