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
PHPでのリーダブルコード/Readable code in PHP
Search
Y-KANOH
March 24, 2022
Technology
2
280
PHPでのリーダブルコード/Readable code in PHP
Y-KANOH
March 24, 2022
Tweet
Share
More Decks by Y-KANOH
See All by Y-KANOH
非エンジニアにも伝えるメールセキュリティ / Email security for non-engineers
ykanoh
16
4.7k
エンジニアは伝え方が9割/90% of what engineers need is communication skills
ykanoh
4
830
PHPカンファレンス関西2024 クロージング/php kansai 2024 closing
ykanoh
0
66
PHPカンファレンス関西2024 オープニング/php kansai 2024 opening
ykanoh
2
260
PHP略語クイズ/PHP Abbreviation Quiz
ykanoh
1
2.5k
PHPカンファレンス関西2024スタッフ希望者向け説明会
ykanoh
0
350
PHPマジックメソッドクイズ!/PHP Magic Method Quiz
ykanoh
0
1.4k
PHPerが再利用可能な情報提供でオフショア先とコード品質向上に取り組む / PHPer try improve the code quality
ykanoh
1
1.2k
どんとこい、PhpStorm 〜Why don't you do IDE's best!〜 / Don't KOI PhpStorm!! Why don't you do IDE's best!!
ykanoh
0
7.5k
Other Decks in Technology
See All in Technology
コードの考古学 〜労務システムから発掘した成長の糧〜
kenta_smarthr
0
1k
Introduction to Bill One Development Engineer
sansan33
PRO
0
240
人とAIとの共創を夢見た2か月 #共創AIミートアップ / Co-Creation with Keito-chan
kondoyuko
1
680
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
8
65k
Redmineの意外と知らない便利機能 (Redmine 6.0対応版)
vividtone
0
1.1k
エンジニアが組織に馴染むために勉強会を主催してチームの壁を越える
ohmori_yusuke
2
110
AIコードエディタは開発を変えるか?Cursorをチームに導入して1ヶ月経った本音
ota1022
1
680
ソフトウェアは捨てやすく作ろう/Let's make software easy to discard
sanogemaru
10
5.7k
AIオンボーディングとAIプロセスマイニング
nrryuya
5
1.3k
データ戦略部門 紹介資料
sansan33
PRO
1
3.1k
プラットフォームとしての Datadog / Datadog as Platforms
aoto
PRO
1
330
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.2k
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
5
620
How to Think Like a Performance Engineer
csswizardry
23
1.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
34k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
1
77
The Art of Programming - Codeland 2020
erikaheidi
54
13k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Practical Orchestrator
shlominoach
188
11k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
Scaling GitHub
holman
459
140k
Transcript
PHPでの リーダブルコード
加納 悠史 カノウユウジ PHPer @Ykanoh65 株式会社 ラクス
PHP使っている人
PHP使っていない人
PHPは変な言語? メリット ▰ すぐ使える ▰ 曖昧な書き方でもすぐ動く 5
PHPは変な言語? デメリット ▰ 曖昧なままなのでバグが起きやすい ▰ 変な記述でもとりあえず動く 6
デメリット回避のために
テクニックが必要
PHPで バグを減らす 記述方 9
1. PHPDoc ▰ 関数やクラスに記載するコメント ▰ PHPでは "型を指定する" ために使用 10
None
1. PHPDoc ▰ 関数やクラスに記載するコメント ▰ PHPでは "型を指定する" ために使用 ▰ 言語仕様以外で型が指定できる貴重なツール
12
2. 名前付き引数 ▰ PHP8.0 の新機能 ▰ 現在の最新は PHP8.1 ▰ 引数の初期値指定の煩雑さを回避
13
function hoge($startIndex=0, $num=0, $max=10, $min=1) { // ... } hoge(3,
12, 11); // min にはデフォルト値の 1 が入る hoge(0, 0, 10, 5); // min だけデフォルト値でないものを入れる場合に煩雑 hoge(min:5); // PHP 8.0 ではこのように書ける hoge(startIndex:3, num:12, max:11, min:1); // デフォルト値以外でも引数の意味がわかりやすくなる
2. 名前付き引数 ▰ PHP8.0 の新機能 ▰ 引数の初期値指定の煩雑さを回避 ▰ ぱっと見で引数の意味を理解できる IDE使ってたら不要かもしれないが...
15
PhpStorm の場合
3. PSR ▰ PHPの規約集 ▰ 複数のルールが存在 ▰ プロジェクトで採用ルールを選んで利用 17
https://www.php-fig.org/psr/
まとめ ▰ PHPDoc ▰ 名前付き引数 ▰ PSR 19