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

主頁 > 知識(shí)庫 > 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) 杭州語音電銷機(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)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。

  • 相關(guān)文章
  • 下面列出與本文章《PHP的new static和new self的區(qū)別與使用》相關(guān)的同類信息!
  • 本頁收集關(guān)于PHP的new static和new self的區(qū)別與使用的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 溧水县| 定南县| 临澧县| 临漳县| 静宁县| 阜新| 平陆县| 雷州市| 长葛市| 惠东县| 海林市| 霸州市| 富锦市| 毕节市| 高青县| 台中县| 中阳县| 西昌市| 广灵县| 永年县| 山阳县| 甘孜县| 盱眙县| 邯郸县| 临沂市| 清水县| 布拖县| 正镶白旗| 宁明县| 交城县| 孝感市| 富宁县| 嵊泗县| 乳山市| 衡阳市| 新宁县| 泸州市| 屏山县| 衡山县| 玛曲县| 宁津县|