owned this note changed 5 years ago
Linked with GitHub

要起飛了!快速了解 PHP 8 大進化

講者:周建毅 Miles Chou

歡迎來到 LaravelConf Taiwan 2020 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

共筆入口:https://hackmd.io/@LaravelTaiwan/Conf2020
手機版請點選上方 按鈕展開議程列表。

大綱

5 年前發布的 PHP 7 做了非常多改變,同時讓我們開始對 PHP 有不一樣的看法。5 年後的今天,PHP 8 也即將要發布了,它將會帶來什麼驚喜,就讓我們一起來看看吧!

議程筆記

開始之前

  • PHP 已經 25 歲了(Java, JavaScript, Delphi)

效能提升

什麼是 JIT?

  • Just in time (動態編譯)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    • Opcache 可以把編譯好的 Opcode 快取起來,留到下次使用
    • Preloading 可以在執行前把 PHP 編譯成 Opcode
    • DynASM 可以把 Opcode 編譯成機器碼
  • 為何不使用 AOT
    • PHP opcode type 是弱型別,由 Zend VM 做型別檢查
    • 型別檢查編譯成機器碼執行,反而會更慢
    • 把所有型別一次檢查完再全部邊譯,則在編譯時會耗費 CPU 資源
  • JIT 使用限制
    • 限 x86
    • CPU-bound
    • 理論上「強型別」會提升效能
  • Demo
    • 效能提升 30% !
  • 建議
    • 多使用並習慣強型別寫法
    • 先了解 CPU-bound ,程式哪裡與 CPU-bound 有關
    • 考慮要不要升 PHP8

WeakMaps

語法擴充

Match Expression

Constructor Property Promotion

Attributes

從 PHPDOC 改成語法直接 tag

Allow ::class on object

$object::class

non-capturing catches

強型別

Mixed type

Union types

Static return type

用 static 表示 return self

Add stringable interface

嚴格 code

Consistent type errors for internal functions

Stricter type checks

var_dump([] % [42]); // int(0)

內建套件

get_debug_type v.s. gettype()

新增 str_* 函式

Built0in extension / class 調整

PHP 的未來

Pattern match

Pipe operator

Conditional return

Partial function application

Select a repo