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で導入されるmatch式 / php8_match
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
kuwacchi
September 25, 2020
Technology
360
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PHP8で導入されるmatch式 / php8_match
PHP8で導入されるmatch式についての発表した内容です。
kuwacchi
September 25, 2020
More Decks by kuwacchi
See All by kuwacchi
おすすめの技術書 LT会_リファクタリング(第2版)/LT_refactor
kuwacchi
0
22k
スモークE2Eテストで20年モノのシステムからバグを燻し出す方法 / smokeE2E
kuwacchi
0
2.2k
Other Decks in Technology
See All in Technology
20260912_スクラムにジェネラリストは必要か
ryugen04
0
400
AI時代、データエンジニアが一番おもろい
genshun9
0
530
The Agent Builder Loop from Daily Work to OSS
minorun365
PRO
3
170
絵ではじめるKubernetesセキュリティ
aoi1
3
460
Podは生きているのにGoだけが落ちる:GOGCとGOMEMLIMITで追うInvisible OOM Killの謎
tkc66buzz
1
710
【技術的負債conf】事業成長に伴う技術的負債の説明責任とAIによるモニタリング、認知的負債について
i35_267
2
870
What the customer really needed
kawaguti
PRO
1
110
Claude in Chrome 入門 / Introduction to Claude in Chrome
cielo1985
0
730
GoCon2026 - Open Source, Open World
sanposhiho
4
4.1k
AIを活用するために決めた "やらないこと" - 価値に注目する / Not betting on AI
soudai
PRO
1
500
20260912_スクフェス三河
kgnkhkr
0
350
[2026-09-11]SREは誰のもの?運用エンジニアが始める 「SRE領域への越境」とチームの進化の軌跡 〜Road to NEXT CRE
tosite
0
210
Featured
See All Featured
Un-Boring Meetings
codingconduct
0
420
Designing for Timeless Needs
cassininazir
1
470
Bash Introduction
62gerente
615
220k
Thoughts on Productivity
jonyablonski
76
5.4k
Darren the Foodie - Storyboard
khoart
PRO
3
3.9k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Paper Plane (Part 1)
katiecoart
PRO
1
11k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.8k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
For a Future-Friendly Web
brad_frost
183
10k
Transcript
#phpltjam ©2020 RAKUS Co., Ltd. ©2020 RAKUS Co., Ltd. PHP8で導入される
match式 桑原 健悟
#phpltjam ©2020 RAKUS Co., Ltd. 自己紹介 •氏名:桑原 健悟(くわはら けんご) •所属:株式会社ラクス
•お仕事:Mail Dealerの開発
#phpltjam ©2020 RAKUS Co., Ltd. 今日のお話 •https://tech-blog.rakus.co.jp/entry/20200917/php
#phpltjam ©2020 RAKUS Co., Ltd. 今日のお話 PHP8で導入されたmatch式について ・switchとの違いは? ・何が嬉しいの?
#phpltjam ©2020 RAKUS Co., Ltd. お品書き ・match式とは ・matchの特徴 ・値の代入が得意 ・さらばbreak忘れ
・条件忘れにエラーで気付ける ・厳密な比較
#phpltjam ©2020 RAKUS Co., Ltd. ©2020 RAKUS Co., Ltd. match式とは
桑原 健悟
#phpltjam ©2020 RAKUS Co., Ltd. match式とは switchのような分岐の構文 $paramの値で処理を分岐
#phpltjam ©2020 RAKUS Co., Ltd. switchとmatchの違い match switch 返り値 あり
なし breakの記述 不要 必要 各条件の処理 1行でしか書けない ブロックで記述可能 比較 厳密(===) 緩やか(==) どの条件にも当てはまらない場合 エラーになる そのまま実行される
#phpltjam ©2020 RAKUS Co., Ltd. ©2020 RAKUS Co., Ltd. match式の特徴
桑原 健悟
#phpltjam ©2020 RAKUS Co., Ltd. ©2020 RAKUS Co., Ltd. 値の代入が得意
桑原 健悟
#phpltjam ©2020 RAKUS Co., Ltd. switchやifは「文」、matchは「式」 • 文とは • 値を返さない
→ 各条件で代入が必要 • 式とは • 値を返す → 代入忘れが発生しにくい 直接、値の代入はできない 値の代入は1回でいい
#phpltjam ©2020 RAKUS Co., Ltd. ©2020 RAKUS Co., Ltd. さらばbreak忘れ
桑原 健悟
#phpltjam ©2020 RAKUS Co., Ltd. break忘れが起こり得ない • switch:明示的にbreakが必要 • match:breakが存在しない
→ break忘れが起こり得ない
#phpltjam ©2020 RAKUS Co., Ltd. ©2020 RAKUS Co., Ltd. 条件忘れにエラーで気付ける
桑原 健悟
#phpltjam ©2020 RAKUS Co., Ltd. switch ユーザの成績(score)ごとに コマンド($command)を発行 日次処理でコマンドを実行するプログラム
#phpltjam ©2020 RAKUS Co., Ltd. match • matchは条件の網羅性を検査し該当がなければエラーとなる
#phpltjam ©2020 RAKUS Co., Ltd. ©2020 RAKUS Co., Ltd. 厳密な比較
桑原 健悟
#phpltjam ©2020 RAKUS Co., Ltd. 厳密な比較 • 「数値だと思っていたら文字列であり思わぬ分岐に入った」がなくなる
#phpltjam ©2020 RAKUS Co., Ltd. 厳密な比較は常に嬉しい? • PHPの関数が厳密な型を意識した作りでないため、 思わぬバグとなる例を紹介
#phpltjam ©2020 RAKUS Co., Ltd. 厳密な比較は常に嬉しい? 結果:"jpgだよ" 結果:“defaultだよ"
#phpltjam ©2020 RAKUS Co., Ltd. 厳密な比較は常に嬉しい? preg_matchはtrueでなく、1を返す。 → match式ではtrue===1となり、該当してもケースに入らない
#phpltjam ©2020 RAKUS Co., Ltd. まとめ • match式はswitchに比べバグが入りにくい仕様 • 代入忘れしにくい
• break忘れがない • 条件忘れもエラーで気付ける • 厳密な比較は良い面も悪い面もある • 既存コードやPHPの関数の型を把握していないと思わぬバグに繋がる恐れも
#phpltjam ©2020 RAKUS Co., Ltd. ©2020 RAKUS Co., Ltd. ご清聴ありがとうございました
桑原 健悟