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
330
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
17
5.7k
エンジニアは伝え方が9割/90% of what engineers need is communication skills
ykanoh
4
1.2k
PHPカンファレンス関西2024 クロージング/php kansai 2024 closing
ykanoh
0
120
PHPカンファレンス関西2024 オープニング/php kansai 2024 opening
ykanoh
2
320
PHP略語クイズ/PHP Abbreviation Quiz
ykanoh
1
2.8k
PHPカンファレンス関西2024スタッフ希望者向け説明会
ykanoh
0
410
PHPマジックメソッドクイズ!/PHP Magic Method Quiz
ykanoh
0
1.7k
PHPerが再利用可能な情報提供でオフショア先とコード品質向上に取り組む / PHPer try improve the code quality
ykanoh
1
1.3k
どんとこい、PhpStorm 〜Why don't you do IDE's best!〜 / Don't KOI PhpStorm!! Why don't you do IDE's best!!
ykanoh
0
8.1k
Other Decks in Technology
See All in Technology
自己管理型チームと個人のセルフマネジメント 〜モチベーション編〜
kakehashi
PRO
5
2.7k
複雑さを受け入れるか、拒むか? - 事業成長とともに育ったモノリスを前に私が考えたこと #RSGT2026
murabayashi
1
1.8k
コールドスタンバイ構成でCDは可能か
hiramax
0
130
田舎で20年スクラム(後編):一個人が企業で長期戦アジャイルに挑む意味
chinmo
1
1.4k
Redshift認可、アップデートでどう変わった?
handy
1
140
AI Agent Standards and Protocols: a Walkthrough of MCP, A2A, and more...
glaforge
0
170
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.3k
「アウトプット脳からユーザー価値脳へ」がそんなに簡単にできたら苦労しない #RSGT2026
aki_iinuma
11
5k
【Agentforce Hackathon Tokyo 2025 発表資料】みらいシフト:あなた働き方を、みらいへシフト。
kuratani
0
110
Oracle Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
3
350
Scrum Guide Expansion Pack が示す現代プロダクト開発への補完的視点
sonjin
0
600
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
5
61k
Featured
See All Featured
The untapped power of vector embeddings
frankvandijk
1
1.5k
The Curious Case for Waylosing
cassininazir
0
200
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
51
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.5k
Practical Orchestrator
shlominoach
190
11k
We Are The Robots
honzajavorek
0
130
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Embracing the Ebb and Flow
colly
88
4.9k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
46
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.2k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
1
220
30 Presentation Tips
portentint
PRO
1
190
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