四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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). 
聲明靜態(tài)的類變量和方法可以不需要實例化類對象的情況下對他們進行調用。靜態(tài)類不能被類對象調用。(類的靜態(tài)方法可以)。//注意看第一個例子,在一個非靜態(tài)的方法中調用了靜態(tài)的變量。唯一的不同是用了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. 
靜態(tài)聲明必須必須是顯式的聲明。為了兼容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. 
因為靜態(tài)方法不需要實例化類對象來調用,所以偽變量$this在靜態(tài)方法中也是不可用的。 

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. 
實際上,靜態(tài)的方法調用在編譯時已經確定了。(這段我不會翻譯。???不明白???)
求了很久求來的翻譯如下:
------------------------------------------------
實際上,靜態(tài)方法的調用在編譯時解決。當使用一個明確的類名時,方法已經被完全識別而不需要應用繼承規(guī)則。如果由自身調用,那么自身被解析成當前的類,也就是代碼所屬的類。這里也沒有應用繼承規(guī)則。
但是一個新的問題:
這里不一定有繼承產生,為什么會提到繼承規(guī)則?(???不明白????)

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

靜態(tài)成員例:
復制代碼 代碼如下: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"; 

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

Foo::aStaticMethod(); 

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

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

主站蜘蛛池模板: 甜蜜都市| 电影《神盾局特工》| 海滩乱淫欧美aⅴ大片| 风云雄霸天下| 监视韩国电影播放| 李越昕蕾| 轻佻寡妇电影| 电影疯狂| 张绍荣| 一闪一闪亮晶晶钢琴谱简谱| 日本电影芋虫| 洛克线| 大地资源中文字幕第3页| 山东教育电视台直播在线观看| 三寸天堂简谱| 黄视频免费网站| 希崎| 维拉·法梅加| 学前教育科研方法的论文| 成人在线免费高清视频| 苦菜花电视剧| 巴霍巴利王:开端 2015 帕拉巴斯| 打美女光屁股视频网站| 郭馨钰| 搜狐首页网| 何育骏| 荒笛子简谱| 二次元头像少女| 火舞俪人 电影| 新女婿时代电视剧免费观看| 视频你懂| 洛兵| 大秦帝国第一部免费看| 误杀2演员| http://www.douyin.com| 吴燕妮个人资料简介| 宋晓飞| 抖音音乐| 云上的宝石| 爱笑会议室演员表| 久草在现|