Más contenido relacionado La actualidad más candente (20) Similar a [PHP 也有 Day #64] PHP 升級指南 (20) [PHP 也有 Day #64] PHP 升級指南2. ⼤家好!
— {
"name": "shengyou/self-introduction",
"description": "Self intro for PHP meetup",
"authors": [
{
"name": "范聖佑 (Shengyou Fan)",
"company": "JetBrains",
"role": "Developer Advocate",
"email": "shengyou.fan@jetbrains.com",
"homepage": "https://kraftsman.tw"
}
],
"support": {
"facebook": "https://fb.me/shengyoufan",
"telegram": "@shengyou",
"line": "shengyoufan"
}
}
4. • 升級 PHP 的必要與重要性
• PHP 版本發佈與廢棄時間表
• PHP 升級指南
• ⽤ PhpStorm 協助升級
• ⽤ Qodana 確保升級品質
• 其他社群⼯具
本⽇⼤綱
—
5. • 安全性
為什麼要升級 PHP 版本?
—
From Wikipedia (https://en.wikipedia.org/wiki/End-of-life_product)
6. • 安全性
• 效能提升
為什麼要升級 PHP 版本?
—
https://kinsta.com/blog/php-benchmarks/ https://www.php.net/releases/8.1/en.php
9. • 2022 年 11 ⽉所有 7 以下的 PHP 版本全部 EOL
• 2022 年 11 ⽉所有維護中的 PHP 版本都是 8 開頭
• 最新版 Laravel 9 最低要求 PHP 8
驅勢警訊
—
From Laravel News (https://laravel-news.com/laravel-9)
13. • 先指定 PHP 及 Composer
- composer.json
- PHP language level
- PHP Interpreter
- Composer Execution
開⼯之前…
—
16. Homebrew 安裝多版本 PHP
—
$ brew install php
$ brew install php@8.1
$ brew install php@8.0
$ brew install php@7.4
# 極限狀況
$ brew tap shivammathur/php
$ brew install shivammathur/php/php@5.6
17. Scoop 安裝多版本 PHP
—
$ scoop bucket add php
$ scoop install php/php8.1
$ scoop install php/php8.0
$ scoop install php/php7.4
18. Apt 安裝多版本 PHP
—
# 增加 repository
$ apt install software-properties-common
$ add-apt-repository ppa:ondrej/php
$ apt update
# 安裝多版本 PHP
$ apt install php
$ apt install php8.0
$ apt install php7.4
# 指定使⽤的 PHP 版本
$ update-alternatives --config php
20. • 本機安裝 (XAMPP、MAMP、⼿動安裝)
• Package Manager (Homebrew、Scoop、Apt)
• Vagrant (Homestead)
• SSH (遠端機器)
PhpStorm ⽀援的
Interpreter 安裝⽅式
—
21. • 本機安裝 (XAMPP、MAMP、⼿動安裝)
• Package Manager (Homebrew、Scoop、Apt)
• Vagrant (Homestead)
• SSH (遠端機器)
• Docker (Docker、Docker Compose)
PhpStorm ⽀援的
Interpreter 安裝⽅式
—
24. 使⽤ Docker
—
$ docker pull composer
# 注意 Composer 内的 PHP 版本
composer:2.2.4 → PHP 8.1.1
composer:1.9.3 → PHP 7.4.11
composer:1.7.3 → PHP 7.3.8
composer:1.5.1 → PHP 7.1.9
composer:1.5.0 → PHP 7.1.8
26. • 使⽤ PhpStorm 的三⼤排版⼯具
- Reformat
- Rearrange
- Optimize Imports
• 使⽤ PhpStorm 的快速修正 (Quick Fix)
• 使⽤ PhpStorm 的重構⼯具 (Refactoring)
• 使⽤ PhpStorm 的程式碼掃描⼯具 (Code Inspection)
• 使⽤ Qodana 確保升級品質
% PhpStorm ⼯具箱
—
29. Qodana
—
A code quality monitoring platform that allows you to
evaluate the integrity of code. It brings into your CI/
CD pipelines all the smart features you love in the
JetBrains IDEs as well as project-level checks like clone
detection and license audit.
https://www.jetbrains.com/qodana/
30. • JVM (Java, Kotlin)
• PHP (EAP)
• Python (EAP)
• JavaScript (EAP)
• Clone Finder (Experimental)
• License Audit (Experimental)
Qodana 提供的 Linters
—
32. • 使⽤ Rector ⾃動升級
• 使⽤ PHPCompatibility 檢查相容性
% 社群⼯具箱
—
33. 使⽤ Rector ⾃動升級
—
# 安裝 Rector
$ composer require rector/rector --dev
# 設定 Rector
$ ./vendor/bin/rector init
# 執⾏ Rector
$ ./vendor/bin/rector process src
34. 使⽤ PHPCompatibility
—
# composer.json 設定
"require-dev": {
"phpcompatibility/php-compatibility": "*"
},
"scripts": {
"post-install-cmd": "...",
"post-update-cmd" : "..."
}
# 執⾏指令
$ ./vendor/bin/phpcs .
--standard=PHPCompatibility
--runtime-set testVersion 8.1
35. • 為什麼要⾯對 PHP 的版本更新?
• 如何⾯對 PHP 的版本更新?
• 有哪些⼯具可以使⽤?
本⽇回顧
—
36. • PHP 8 語法介紹
• 升級指南
• PhpStorm 新版特⾊
• Qodana Playground
想了解更多?
—