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
PHP 8.0 の新記法を試してみよう!
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Shohei Okada
May 29, 2021
Programming
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PHP 8.0 の新記法を試してみよう!
PHP カンファレンス沖縄 2021
Shohei Okada
May 29, 2021
More Decks by Shohei Okada
See All by Shohei Okada
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
440
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
1.2k
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
2.5k
パスワードのハッシュ、ソルトってなに? - What is hash and salt for password?
okashoi
3
480
設計の考え方 - インターフェースと腐敗防止層編 #phpconfuk / Interface and Anti Corruption Layer
okashoi
11
6.8k
"config" ってなんだ? / What is "config"?
okashoi
0
2.1k
ファイル先頭の use の意味、説明できますか? 〜PHP の namespace と autoloading の関係を正しく理解しよう〜 / namespace and autoloading in php
okashoi
4
2.4k
MySQL のインデックスの種類をおさらいしよう! / overviewing indexes in MySQL
okashoi
0
1.5k
PHP における静的解析(あるいはそもそも静的解析とは) / #phpcondo_yasai static analysis for PHP
okashoi
1
1.6k
Other Decks in Programming
See All in Programming
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
130
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
6
2.2k
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
330
Getting Started with Vibe Coding
miccheng
0
190
SODA - FACT BOOK(JP)
sodainc
1
40k
Spec-driven Development with AI
simas
PRO
0
2.3k
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
240
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
3
1.5k
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
2k
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
320
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
190
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
740
Featured
See All Featured
Designing Experiences People Love
moore
143
24k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Practical Orchestrator
shlominoach
192
12k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
The Curse of the Amulet
leimatthew05
3
17k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
680
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
600
Typedesign – Prime Four
hannesfritz
42
3.2k
Transcript
PHP 8.0 の新記法を 試してみよう! 2021/05/29 PHP カンファレンス沖縄 2021 @okashoi
岡田 正平/おかしょい Twitter: @okashoi GitHub: @okashoi 所属:株式会社ウィルゲート 登壇:
寄稿:
岡田 正平/おかしょい Twitter: @okashoi GitHub: @okashoi 所属:株式会社ウィルゲート 登壇:
寄稿: (バーチャルの姿)
2020/11/26
PHP 8.0 で追加された新しい構文や関数の中から すぐに使えそうなものをピックアップ、勢いにまかせて紹介 この発表のゴール • 聴いた人が PHP
8.0 を使いたくなる • 聴いた人がこの発表で知った構文を実際に使う 本発表の趣旨
本発表は『WEB+DB PRESS vol. 120』に寄稿した 「5 年ぶりの新版!PHP 8 登場」の内容をベースに 5 分間にぎゅっと詰め込んだものです
おことわり ※また、日本語訳は 私の独断によるものです
str_〇〇 関数
str_contains() 関数 <?php var_dump(str_contains('Hello, PHP8!', 'PHP')); var_dump(str_contains('Hello, PHP8!', 'PHP7')); /*
実行結果 bool(true) bool(false) */
str_starts_with(), str_ends_with() 関数 <?php var_dump(str_starts_with('Hello, PHP8!', 'Hello')); var_dump(str_starts_with('Hello, PHP8!', 'PHP8!'));
var_dump(str_ends_with('Hello, PHP8!', 'Hello')); var_dump(str_ends_with('Hello, PHP8!', 'PHP8!')); /* 実行結果 bool(true) bool(false) bool(false) bool(true) */
PHP 7 系以前では...... <?php // str_contains()相当 function my_str_contains(string $a, string
$b): bool { return strpos($a, $b) !== false; } // str_starts_with()相当 function my_str_starts_with(string $a, string $b): bool { return strpos($a, $b) === 0; } // str_ends_with()相当 function my_str_ends_with(string $a, string $b): bool { return strrpos($a, $b) === strlen($a) - strlen($b); }
null 安全演算子
null 安全演算子 ?-> <?php // $user が null の場合もエラーにならない $user?->changeName('okashoi');
// PHP 7 系以前では例えばこうしていた is_null($user) ?: $user->changeName('okashoi');
メソッドをチェインさせたいときに便利 <?php function example1(?Foo $foo): ?FooBar { if(is_null($foo)) { return
null; } $bar = $foo->bar(); if(is_null($bar)) { return null; } $buz = $bar->buz(); if(is_null($buz)) { return null; } return $buz->foobar(); } <?php function example2(?Foo $foo): ?FooBar { return $foo?->bar() ?->buz() ?->foobar(); }
match 式
match 式 <?php $english = match (1) { 1 =>
'one', 2 => 'two', 3 => 'three', default => 'more than three', }; var_dump($english); /* 実行結果 string(3) "one" */ ※ “match” は予約語に
1. 文(statement)ではなく式(expression)であること 2. break を書き忘れる心配がない 3. 厳密比較(===)が用いられる 4. 何にもマッチしないと UnhandledMatchError
を送出 5. 右辺には単一の式しか指定できない(※) ※ Future scope として「ブロック」を指定できるようにする旨の議論あり switch 文との違い
名前付き引数
名前付き引数 <?php function setFullName(string $givenName, string $familyName): void { //
省略 } // familyNameを先に指定できる setFullName(familyName: '岡田', givenName: '正平');
union 型
union 型 <?php // 引数にint型の値もfloat型の値も渡せる // 戻り値はint型またはfloat型のどちらか function square(int|float $x):
int|float { return $x * $x; }
mixed 型
mixed 型 <?php function foo(mixed $value): mixed { return $value;
} array|bool|callable|int|float|null|object|resource|string と同じ
もっと知りたい方は公式ドキュメントをチェック! https://www.php.net/releases/8.0/ WEB+DB PRESS の記事(バックナンバー)もヨロシク まだまだたくさん新機能!
PHP 8.0 で追加された新しい構文や関数の中から すぐに使えそうなものをピックアップ、勢いにまかせて紹介 この発表のゴール • 聴いた人が PHP
8.0 を使いたくなる • 聴いた人がこの発表で知った構文を実際に使う 本発表の趣旨(再掲)