Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PHP8.xの新機能を使ってより良いコードを書こう!
Search
Shunsuke Santo
February 15, 2023
Programming
370
0
Share
PHP8.xの新機能を使ってより良いコードを書こう!
Shunsuke Santo
February 15, 2023
Other Decks in Programming
See All in Programming
運転動画を検索可能にする〜Cosmos-Embed1とDatabricks Vector Searchで〜/cosmos-embed1-databricks-vector-search
studio_graph
1
740
ふにゃっとしない名前の付け方 〜哲学で茹で上げる、コシのあるソフトウェア設計〜
shimomura
0
120
My daily life on Ruby
a_matsuda
3
310
AgentCore Optimizationを始めよう!
licux
3
230
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
300
cloudnative conference 2026 flyle
azihsoyn
0
180
Kubernetesを使わない環境にもCloud Nativeなデプロイを実現する / Enabling Cloud Native deployments without the complexity of Kubernetes
linyows
3
380
Liberating Ruby's Parser from Lexer Hacks
ydah
2
2.7k
ハーネスエンジニアリングにどう向き合うか 〜ルールファイルを超えて開発プロセスを設計する〜 / How to approach harness engineering
rkaga
28
20k
Back to the roots of date
jinroq
0
810
🦞OpenClaw works with AWS
licux
1
350
AIを導入する前にやるべきこと
negima
2
350
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
100
6.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
820
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
61
44k
Testing 201, or: Great Expectations
jmmastey
46
8.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
130
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
190
Google's AI Overviews - The New Search
badams
0
1k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
110
Color Theory Basics | Prateek | Gurzu
gurzu
0
310
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
1.3k
Transcript
PHP8.xの新機能を使って より良いコードを書こう! 山藤駿亮 Qiita: @SanQ Twitter: @SAshunchan
PHPは7→8へ このLTではPHP8.0からの新機能を紹介
今回紹介する新機能 • コンストラクタ • 名前付き引数 • Match式
コンストラクタ(8.0~) <機能> • プロパティのアクセス権を引数内で 設定できる • プロパティへの代入をコンストラクタ の引数内で行える → コンストラクタにかける記述量が減少
例:string(10) "hello! PHP" を出力 PHP 7.4
例:string(10) "hello! PHP" を出力 PHP 8.0
名前付き引数 (8.0~) <機能> • メソッドの引数に名前を付けられる • メソッドの引数の順序を守らなくても良い • デフォルトの値がある引数は実行時に 値を入れる必要がない → 使用される引数の内容がより分かりや
すい
例:全ての引数を合計した結果を出力 PHP 7.4 PHP 8.0
名前付き引数の注意点 名前付き引数を使用した場合、その後の 引数も名前付き引数を使用しなくてはな らない 上の結果 Error: Cannot use positional argument
after named argument
Match式 (8.0~) <機能> • 条件分岐を文ではなく式として処理する • 条件部分に条件外の値が来た場合エ ラーを吐く • 値の比較は厳密な比較 → 少ない記述かつ厳密な比較で条件分
岐を実装可能になった
例:$numberの値によって$resultの値を変更 PHP 7.4 PHP 8.0
Match式の注意点 • switchは緩やかな比較である一方で Match式は厳密な比較。※ • match式内部で式の実行はできない → switchからmatch式に書き換える際は 注意が必要 ※引数にtrueを入れることでmatch式でも緩やかな比較が可能
最後に… • より柔軟な型の定義やコードの短縮が 可能に! • パフォーマンスが向上! 一部の仕様が変更しているためバージョ ンアップの際は公式のドキュメントを参照 することが重要
参考資料 PHP Supported Versions (https://www.php.net/supported-versions.php) PHP8 released(https://www.php.net/releases/8.0/ja.php) PHP match() (https://www.php.net/manual/ja/control-
structures.match.php) Qiita @rana_kualu 【PHP8.0】PHP8.0の新機能 (https://qiita.com/rana_kualu/items/a6601b49e0591eb42200) PHP 7.4.x から PHP 8.0.x への移行(https://www.php.net/migration80)
ご清聴ありがとうございました! 今日の内容の詳細や追加 情報を記事にしています! (右のQRまたは https://qiita.com/SanQ/ite ms/f8453d6a7cbac6852312)