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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Shunsuke Santo
February 15, 2023
Programming
0
350
PHP8.xの新機能を使ってより良いコードを書こう!
Shunsuke Santo
February 15, 2023
Tweet
Share
Other Decks in Programming
See All in Programming
AgentCoreとHuman in the Loop
har1101
5
250
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
330
今から始めるClaude Code超入門
448jp
8
9.1k
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
CSC307 Lecture 10
javiergs
PRO
1
660
CSC307 Lecture 04
javiergs
PRO
0
660
Apache Iceberg V3 and migration to V3
tomtanaka
0
170
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
230
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
470
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
150
CSC307 Lecture 02
javiergs
PRO
1
780
Claude Codeと2つの巻き戻し戦略 / Two Rewind Strategies with Claude Code
fruitriin
0
150
Featured
See All Featured
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
Code Review Best Practice
trishagee
74
20k
Paper Plane (Part 1)
katiecoart
PRO
0
4.3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
130
Into the Great Unknown - MozCon
thekraken
40
2.3k
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Raft: Consensus for Rubyists
vanstee
141
7.3k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
240
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
950
The SEO Collaboration Effect
kristinabergwall1
0
360
How to make the Groovebox
asonas
2
1.9k
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)