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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Y-KANOH
March 24, 2022
Technology
360
2
Share
PHPでのリーダブルコード/Readable code in PHP
Y-KANOH
March 24, 2022
More Decks by Y-KANOH
See All by Y-KANOH
君はジョシュアツリーを知っているか?名前をつけて事象を正しく認識しよう / Do you know Joshua Tree?
ykanoh
4
160
非エンジニアにも伝えるメールセキュリティ / Email security for non-engineers
ykanoh
18
6.1k
エンジニアは伝え方が9割/90% of what engineers need is communication skills
ykanoh
4
1.4k
PHPカンファレンス関西2024 クロージング/php kansai 2024 closing
ykanoh
0
150
PHPカンファレンス関西2024 オープニング/php kansai 2024 opening
ykanoh
2
350
PHP略語クイズ/PHP Abbreviation Quiz
ykanoh
1
2.9k
PHPカンファレンス関西2024スタッフ希望者向け説明会
ykanoh
0
440
PHPマジックメソッドクイズ!/PHP Magic Method Quiz
ykanoh
0
1.8k
PHPerが再利用可能な情報提供でオフショア先とコード品質向上に取り組む / PHPer try improve the code quality
ykanoh
1
1.4k
Other Decks in Technology
See All in Technology
Google Cloud Next '26 の裏でこっそりリリースされたCloud Number Registry & Cloud Hub コスト分析 を試してみた
hikaru1001
0
140
小説執筆のハーネスエンジニアリング
yoshitetsu
0
890
Shipping AI Agents — Lessons from Production
vvatanabe
0
300
AI バイブコーティングでキーボード不要?!
samakada
0
670
Choose your own adventure in agentic design patterns
glaforge
0
160
AgentCore×VPCでの設計パターンn選と勘所
har1101
4
360
知ってた?JavaScriptの"正しさ"を検証するテストが5万以上もあること(Test262)
riyaamemiya
0
100
M5Stack CoreS3とZephyr(RTOS)で Edge AIっぽいことしてみた
iotengineer22
0
400
Fabric MCPの紹介と使い分け
ryomaru0825
1
110
20260423_執筆の工夫と裏側 技術書の企画から刊行まで / From the planning to the publication of technical book
nash_efp
3
690
COBOL婆さんの伝説
poropinai1966
0
130
Forget technical debt
ufried
0
140
Featured
See All Featured
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
680
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
10k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.4k
sira's awesome portfolio website redesign presentation
elsirapls
0
230
Context Engineering - Making Every Token Count
addyosmani
9
850
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
150
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
780
Building Flexible Design Systems
yeseniaperezcruz
330
40k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
From π to Pie charts
rasagy
0
180
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
450
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