Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PHP8.xの新機能を使ってより良いコードを書こう!
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Shunsuke Santo
February 15, 2023
Programming
400
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PHP8.xの新機能を使ってより良いコードを書こう!
Shunsuke Santo
February 15, 2023
Other Decks in Programming
See All in Programming
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
330
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
4
400
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
600
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
440
AWSに止められる覚悟してますか?
morizo_1984
2
490
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
120
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1k
カツオ、ご期待ください
suneo3476
0
120
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
250
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.2k
Agents on Rails - Rails at Scale 2026
irinanazarova
0
300
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
450
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
290
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
750
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Six Lessons from altMBA
skipperchong
29
4.5k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.2k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
520
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
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)