婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > PHP的new static和new self的區(qū)別與使用

PHP的new static和new self的區(qū)別與使用

熱門標(biāo)簽:天潤(rùn)融通外呼系統(tǒng)好嗎 高德地圖標(biāo)注位置怎么標(biāo)注 欣思維地圖標(biāo)注 泊頭在哪里辦理400電話 江門回?fù)芡夂粝到y(tǒng) 杭州語(yǔ)音電銷機(jī)器人 高德地圖標(biāo)注店鋪收費(fèi)嗎 電銷機(jī)器人沒有效果怎么樣 江西電銷機(jī)器人收費(fèi)

下面我們舉個(gè)栗子:

class Father {
  public static function getSelf() {
    return new self();
  }

  public static function getStatic() {
    return new static();
  }
}

class Son extends Father {}

echo get_class(Son::getSelf()); // Father
echo get_class(Son::getStatic()); // Son
echo get_class(Father::getSelf()); // Father
echo get_class(Father::getStatic()); // Father

new self

這里面注意這一行 get_class(Son::getStatic()); 返回的是 Son 這個(gè) class, 可以總結(jié)如下:
self 返回的是 new self 中關(guān)鍵字 new 所在的類中,比如這里例子的 :

public static function getSelf() {
  return new self(); // new 關(guān)鍵字在 Father 這里
}

始終返回 Father。

new static

static 則上面的基礎(chǔ)上,更聰明一點(diǎn)點(diǎn):static 會(huì)返回執(zhí)行 new static() 的類,比如 Son 執(zhí)行 get_class(Son::getStatic()) 返回的是 Son, Father 執(zhí)行 get_class(Father::getStatic()) 返回的是 Father

而在沒有繼承的情況下,可以認(rèn)為 new self 和 new static 是返回相同的結(jié)果。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • PHP面向?qū)ο蟪绦蛟O(shè)計(jì)中的self、static、parent關(guān)鍵字用法分析
  • php面向?qū)ο蟪绦蛟O(shè)計(jì)中self與static的區(qū)別分析
  • PHP面向?qū)ο笾衝ew self()與 new static()的區(qū)別淺析
  • 淺談PHP中new self()和new static()的區(qū)別
  • PHP Class self 與 static 異同與使用詳解

標(biāo)簽:雙鴨山 石嘴山 內(nèi)江 深圳 駐馬店 大同 江門 巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP的new static和new self的區(qū)別與使用》,本文關(guān)鍵詞  PHP,的,new,static,和,self,區(qū)別,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。

  • 相關(guān)文章
  • 下面列出與本文章《PHP的new static和new self的區(qū)別與使用》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于PHP的new static和new self的區(qū)別與使用的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 娄烦县| 永顺县| 盱眙县| 南部县| 赣州市| 房山区| 田阳县| 堆龙德庆县| 玉山县| 邹平县| 蒙自县| 沾化县| 淮北市| 和顺县| 扎鲁特旗| 深州市| 灵武市| 牟定县| 英超| 民丰县| 揭阳市| 大洼县| 珠海市| 八宿县| 巴塘县| 金沙县| 淄博市| 通化市| 辽阳市| 修文县| 南陵县| 麟游县| 巴彦县| 高青县| 恩平市| 崇州市| 梓潼县| 瓮安县| 博兴县| 徐水县| 班玛县|