一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

php基礎知識:類與對象(5) static

Declaring class members or methods as static makes them accessible without needing an instantiation of the class. A member declared as static can not be accessed with an instantiated class object (though a static method can). 
聲明靜態的類變量和方法可以不需要實例化類對象的情況下對他們進行調用。靜態類不能被類對象調用。(類的靜態方法可以)。//注意看第一個例子,在一個非靜態的方法中調用了靜態的變量。唯一的不同是用了self。難道用了self就可以????不知道???需要一個試驗。

The static declaration must be after the visibility declaration. For compatibility with php4, if no visibility declaration is used, then the member or method will be treated as if it was declared as public. 
靜態聲明必須必須是顯式的聲明。為了兼容php4,如果沒有顯式聲明的對象或者方法,被當作聲明為public。

Because static methods are callable without an instance of the object created, the pseudo variable $this is not available inside the method declared as static. 
因為靜態方法不需要實例化類對象來調用,所以偽變量$this在靜態方法中也是不可用的。 

In fact static method calls are resolved at compile time. When using an explicit class name the method is already identified completely and no inheritance rules apply. If the call is done by self then self is translated to the current class, that is the class the code belongs to. Here also no inheritance rules apply. 
實際上,靜態的方法調用在編譯時已經確定了。(這段我不會翻譯。???不明白???)
求了很久求來的翻譯如下:
------------------------------------------------
實際上,靜態方法的調用在編譯時解決。當使用一個明確的類名時,方法已經被完全識別而不需要應用繼承規則。如果由自身調用,那么自身被解析成當前的類,也就是代碼所屬的類。這里也沒有應用繼承規則。
但是一個新的問題:
這里不一定有繼承產生,為什么會提到繼承規則?(???不明白????)

Static properties cannot be accessed through the object using the arrow operator ->. Calling non-static methods statically generates an E_STRICT level warning. 
靜態成員不能被類的對象通過箭頭符號->來調用。靜態的調用一個非靜態方法會導致一個E_STRICT級別的警告。

靜態成員例:
復制代碼 代碼如下:class Foo 

   public static $my_static = 'foo';  
   public function staticValue() { 
       return self::$my_static;//注意這里!!!! 
       //return $my_static;//這樣寫會不會出錯。需要試驗 
   } 


class Bar extends Foo 

   public function fooStatic() { 
       return parent::$my_static;//注意這里!!!! 
   } 

print Foo::$my_static . " n"; 
$foo = new Foo(); 
print $foo->staticValue() . " n"; 
print $foo->my_static . " n";      // 未定義的"Property" my_static  
// $foo::my_static is not possible 
print Bar::$my_static . " n"; 
$bar = new Bar(); 
print $bar->fooStatic() . " n"; 

靜態方法例: 
class Foo { 
   public static function aStaticMethod() { 
       // ... 
   } 

Foo::aStaticMethod(); 

php技術php基礎知識:類與對象(5) static,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 色女人综合 | 一级毛片特黄久久免费看 | 亚洲欧洲综合 | 久久ww精品w免费人成 | 国产小视频在线免费观看 | 国产91精品久久久久久久 | 国产成人精品久久一区二区小说 | 成人观看天堂在线影片 | 91香蕉国产亚洲一二三区 | 欧美日本一二三区 | 欧美7777 | 精品自拍视频在线观看 | 色综合色综合色综合色综合 | 女人被爽到呻吟娇喘的视频动态图 | 婷婷色爱区综合五月激情韩国 | 2021国内精品久久久久久影院 | 成人tv| 日本理论午夜中文字幕第一页 | 免费91麻豆精品国产自产在线观看 | 最近更新中文字幕第一页 | 日本在线一区二区 | 欧美黄色片在线观看 | 久久九九青青国产精品 | 亚洲特一级毛片 | 伊人小婷婷色香综合缴缴情 | 涩涩涩涩爱 | 六月婷婷啪啪 | 美女一级毛片免费看看 | 怡红院日本 | 男女牲交一级毛片 | 欧美日韩亚洲国产无线码 | 91短视频免费在线观看 | 亚洲国产精品自在在线观看 | 视频国产一区 | 婷婷丁香五月中文字幕 | 人人干免费| 国产精品欧美亚洲韩国日本久久 | 99国产精品九九视频免费看 | 婷婷影院在线综合免费视频 | 日日摸夜夜添夜夜添人人爽 | 日韩第一色 |