好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > PHP 8新特性簡介

PHP 8新特性簡介

熱門標簽:地圖標注符號樣式有 菏澤語音外呼系統(tǒng)運營商 廈門400電話辦理選易號網(wǎng) 公司外呼系統(tǒng)中心 電子地圖標注怎么修改 臨沂crm外呼系統(tǒng)平臺 梧州市機器人外呼系統(tǒng)怎么樣 天客通地圖標注 如何在世界地圖標注

PHP 8新特性

新的主要PHP版本PHP 8預(yù)計將于2020年底發(fā)布。它現(xiàn)在處于非?;钴S的開發(fā)階段,所以在接下來的幾個月里,事情可能會發(fā)生很大的變化。

在這篇文章中,我將持續(xù)更新預(yù)期的內(nèi)容列表:新特性、性能改進和重大變化。因為PHP 8是一個新的主版本,所以您的代碼被破壞的幾率更高。如果你一直在更新最新的版本,升級應(yīng)該不會太困難,因為大多數(shù)有破壞性的更改在7之前就已經(jīng)廢棄了。*版本。

除了中斷更改之外,PHP 8還帶來了一些不錯的新特性,比如JIT編譯器和union類型;還有更多!

Union types:聯(lián)合類型

考慮到PHP的動態(tài)類型化特性,在很多情況下聯(lián)合類型是有用的。聯(lián)合類型是兩個或多個類型的集合,這些類型表示其中一個可以使用。

public function foo(Foo|Bar $input): int|float;

注意,void永遠不能是union類型的一部分,因為它表示“根本沒有返回值”。此外,可以使用|null來編寫可為空的聯(lián)合,也可以使用現(xiàn)有的?符號:

public function foo(Foo|null $foo): void;

public function bar(?Bar $bar): void;

JIT

即時編譯器承諾顯著的性能改進,盡管并不總是在web請求的上下文中。目前還沒有任何準確的基準,但它們肯定會到來。

Static return type:靜態(tài)的返回類型

雖然已經(jīng)可以返回self,但靜態(tài)類型直到PHP 8才成為有效的返回類型。考慮到PHP的動態(tài)類型特性,這一特性對許多開發(fā)人員都很有用。

class Foo
{
  public function test(): static
  {
    return new static();
  }
}

Weak maps

在PHP 7.4中添加的weakrefs RFC的基礎(chǔ)上,在PHP 8中添加了WeakMap實現(xiàn)。弱映射包含對對象的引用,這并不會阻止那些對象被垃圾收集。

以orm為例,它們通常實現(xiàn)保存對實體類的引用的緩存,以改進實體之間關(guān)系的性能。這些實體對象不能被垃圾回收,只要這個緩存有一個對它們的引用,即使緩存是唯一引用它們的東西。

如果這個緩存層使用弱引用和映射,那么PHP將在沒有其他對象引用它們時對這些對象進行垃圾收集。尤其是orm,它可以在一個請求中管理數(shù)百個(如果不是數(shù)千個)實體;弱映射為處理這些對象提供了一種更好的、對資源更友好的方法。

下面是弱映射的樣子,一個來自RFC的例子:

class Foo 
{
  private WeakMap $cache;

  public function getSomethingWithCaching(object $obj): object
  {
    return $this->cache[$obj]
      ??= $this->computeSomethingExpensive($obj);
  }
}

::class on objects

一個小而有用的新特性:現(xiàn)在可以在對象上使用::class,而不必在對象上使用get_class()。它的工作方式與get_class()相同。

$foo = new Foo();

var_dump($foo::class);

Stringable interface

Stringable接口可用于鍵入提示任何字符串或?qū)崿F(xiàn)了 tostring()的內(nèi)容。而且,無論何時類實現(xiàn)了 tostring(),它都會在后臺自動實現(xiàn)接口,不需要手動實現(xiàn)。

class Foo
{
  public function __toString(): string
  {
    return 'foo';
  }
}

function bar(Stringable $stringable) { /* … */ }

bar(new Foo());
bar('abc');

從接口創(chuàng)建DateTime對象

您已經(jīng)可以使用DateTime:: createfromimmutabledatetime ($immutableDateTime)從一個datetime對象創(chuàng)建一個DateTime對象,但是另一種方法比較麻煩。通過添加DateTime::createFromInterface()和datetime::createFromInterface(),現(xiàn)在就有了一種將DateTime和datetime對象相互轉(zhuǎn)換的通用方法。

DateTime::createFromInterface(DateTimeInterface $other);

DateTimeImmutable::createFromInterface(DateTimeInterface $other);

重新定義引擎的警告

許多以前只觸發(fā)警告或通知的錯誤現(xiàn)在已經(jīng)轉(zhuǎn)換為正確的錯誤。以下警告已更改。

  • Undefined variable: Error exception instead of notice
  • Undefined array index: warning instead of notice
  • Division by zero: DivisionByZeroError exception instead of warning
  • Attempt to increment/decrement property ‘%s' of non-object: Error exception instead of warning
  • Attempt to modify property ‘%s' of non-object: Error exception instead of warning
  • Attempt to assign property ‘%s' of non-object: Error exception instead of warning
  • Creating default object from empty value: Error exception instead of warning
  • Trying to get property ‘%s' of non-object: warning instead of notice
  • Undefined property: %s::$%s: warning instead of notice
  • Cannot add element to the array as the next element is already occupied: Error exception instead of warning
  • Cannot unset offset in a non-array variable: Error exception instead of warning
  • Cannot use a scalar value as an array: Error exception instead of warning
  • Only arrays and Traversables can be unpacked: TypeError exception instead of warning
  • Invalid argument supplied for foreach(): TypeError exception instead of warning
  • Illegal offset type: TypeError exception instead of warning
  • Illegal offset type in isset or empty: TypeError exception instead of warning
  • Illegal offset type in unset: TypeError exception instead of warning
  • Array to string conversion: warning instead of notice
  • Resource ID#%d used as offset, casting to integer (%d): warning instead of notice
  • String offset cast occurred: warning instead of notice
  • Uninitialized string offset: %d: warning instead of notice
  • Cannot assign an empty string to a string offset: Error exception instead of warning

以上就是PHP 8新特性簡介的詳細內(nèi)容,更多關(guān)于php 8新特性的資料請關(guān)注腳本之家其它相關(guān)文章!

您可能感興趣的文章:
  • 簡述PHP7.4 新特性和廢棄的功能
  • php7新特性的理解和比較總結(jié)
  • PHP5.5新特性之yield理解與用法實例分析
  • php7函數(shù),聲明,返回值等新特性介紹
  • PHP新特性之字節(jié)碼緩存和內(nèi)置服務(wù)器
  • PHP新特性詳解之命名空間、性狀與生成器
  • PHP7新特性簡述
  • php 7新特性之類型申明詳解
  • 聊聊 PHP 8 新特性 Attributes

標簽:郴州 貴陽 雞西 白城 黃石 瀘州 迪慶 綿陽

巨人網(wǎng)絡(luò)通訊聲明:本文標題《PHP 8新特性簡介》,本文關(guān)鍵詞  PHP,新特性,新,特性,簡介,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PHP 8新特性簡介》相關(guān)的同類信息!
  • 本頁收集關(guān)于PHP 8新特性簡介的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 久久伊人热精品老鸭窝| 亚洲人成网站在线在线| 巜少妇的奶水2中文版免费观看| 99精品视频在线播放| 美女搞黄软件免费高清看| 国产精品666| 欧美日韩国产精品成人AV电影| 欧美猛交xxxxx| 日本无码av福利写真| 乖乖张开腿让我亲欲欲成欢| 我半夜摸丰满亲妺妺C了她| 午夜性色一区二区三区不卡视频| 亲爱的老师韩国| 国产一级久久久久久毛片| 一级毛片免费播放一区二区| 农村妇女愉情伦理| 欧美性老太| 穿超短裙故意没有穿内裤小说 | 皇上跪在龙椅前挨c高H催眠| 邻居交换夫妇4中文字幕| 噜噜噜噜噜噜色| 国产亚洲新品一区二区| 在线观看十八禁视频| 欧美小电影| 亚洲精品欧美日韩| 91极品尤物国产在线播放| free俄罗斯性xxhd| 男女互摸很爽下面出水动态图 | 私人玩物麻酥酥自慰喷水| 两女人互添下身口口小视频| 成人黄色三级视频| 一区二区三区免费| 一边吃奶一边添p好爽视频第9季| 大雞巴亂倫第二部在线阅读| 国产视频毛片| 亚洲综合久久一本伊伊区| 一级作爱视频| 日本丶国产丶欧美色综合| 国产艹逼| 欧洲一区二区三区久久久| 五级牲爱片|