$30 off During Our Annual Pro Sale. View Details »
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
320
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
110
PHPカンファレンス関西2024 オープニング/php kansai 2024 opening
ykanoh
2
320
PHP略語クイズ/PHP Abbreviation Quiz
ykanoh
1
2.8k
PHPカンファレンス関西2024スタッフ希望者向け説明会
ykanoh
0
400
PHPマジックメソッドクイズ!/PHP Magic Method Quiz
ykanoh
0
1.6k
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
Snowflake導入から1年、LayerXのデータ活用の現在 / One Year into Snowflake: How LayerX Uses Data Today
civitaspo
0
2.4k
「図面」から「法則」へ 〜メタ視点で読み解く現代のソフトウェアアーキテクチャ〜
scova0731
0
500
テストセンター受験、オンライン受験、どっちなんだい?
yama3133
0
170
ActiveJobUpdates
igaiga
1
320
Oracle Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
1
410
SQLだけでマイグレーションしたい!
makki_d
0
1.2k
MySQLとPostgreSQLのコレーション / Collation of MySQL and PostgreSQL
tmtms
1
1.2k
業務の煩悩を祓うAI活用術108選 / AI 108 Usages
smartbank
9
12k
M&Aで拡大し続けるGENDAのデータ活用を促すためのDatabricks権限管理 / AEON TECH HUB #22
genda
0
240
通勤手当申請チェックエージェント開発のリアル
whisaiyo
3
470
Connection-based OAuthから学ぶOAuth for AI Agents
flatt_security
0
370
AgentCoreとStrandsで社内d払いナレッジボットを作った話
motojimayu
1
970
Featured
See All Featured
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.1k
Bash Introduction
62gerente
615
210k
Color Theory Basics | Prateek | Gurzu
gurzu
0
150
Technical Leadership for Architectural Decision Making
baasie
0
180
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
70k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.1k
The Curse of the Amulet
leimatthew05
0
4.8k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
130
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
110
We Are The Robots
honzajavorek
0
120
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
110
30 Presentation Tips
portentint
PRO
1
170
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