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
390
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
280
非エンジニアにも伝えるメールセキュリティ / Email security for non-engineers
ykanoh
18
6.7k
エンジニアは伝え方が9割/90% of what engineers need is communication skills
ykanoh
4
1.6k
PHPカンファレンス関西2024 クロージング/php kansai 2024 closing
ykanoh
0
180
PHPカンファレンス関西2024 オープニング/php kansai 2024 opening
ykanoh
2
380
PHP略語クイズ/PHP Abbreviation Quiz
ykanoh
1
3.1k
PHPカンファレンス関西2024スタッフ希望者向け説明会
ykanoh
0
470
PHPマジックメソッドクイズ!/PHP Magic Method Quiz
ykanoh
0
1.9k
PHPerが再利用可能な情報提供でオフショア先とコード品質向上に取り組む / PHPer try improve the code quality
ykanoh
1
1.5k
Other Decks in Technology
See All in Technology
MIXIで活躍できるエンジニアを 若手社員目線で考えてみる
mixi_engineers
PRO
0
110
RapidCopy2 Matrix I/Oエンジンによるファイルコピーソフトウェアの設計と実装
kengosawa2
1
180
Sets in Go
ramalho
1
1.2k
MulticaとPi Coding Agentで、小規模OSSを30本同時運用した流れ
eiei114
0
140
What's new in Go 1.27?
ciarana
0
290
Kiro入門|仕様駆動開発で変わるAI時代の開発スタイル
cmkudo
0
290
Master Dataグループ紹介資料
sansan33
PRO
1
4.8k
ハッカソンで入賞した話 @ Findy LT
asari194617
0
1.4k
作って理解するCoding Agent 〜フレームワークに頼らないピュア Python での実装〜
takapy
3
750
AIコーディングの次。コードレビューと理解負荷を解消して組織の開発生産性を高める
moongift
PRO
2
2.7k
巨大気象データと戦う ― サロゲートモデル学習を高速化する圧縮技術
gpuunite_official
0
190
AI画像認識を活用したゲーム内決済処理検証の自動化
gree_tech
PRO
0
110
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
210
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
470
Raft: Consensus for Rubyists
vanstee
141
7.6k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
KATA
mclloyd
PRO
35
15k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.4k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
340
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
Tell your own story through comics
letsgokoyo
1
1k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
500
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