1
例如,在請求的整個生命週期中,類中的靜態變量是否會持續存在?
class Foo
{
private static $my_static;
public static function staticValue() {
if (self::$my_static === null) {
self::$my_static = 'foo';
}
return self::$my_static;
}
}
的Foo::staticValue()
第一個電話將設置$my_static
到foo
,並Foo::staticValue()
的後續調用將不會進入if
聲明的身體,但返回foo
的時候了。那是對的嗎?
這是正確的。 – 2010-11-01 19:15:16