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
楽をするためのPHPDocと配列型の落とし穴 / PHPDoc and pitfalls of...
Search
takaram
August 24, 2020
Programming
5.7k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
楽をするためのPHPDocと配列型の落とし穴 / PHPDoc and pitfalls of array
takaram
August 24, 2020
More Decks by takaram
See All by takaram
レガシーシステムに自動テストを導入する第一歩 / 2020-phpcon-tdd-in-legacy-product
takaram
1
3.4k
Other Decks in Programming
See All in Programming
이 함수, 실패하면 어떻게 되나요? null부터 Rich Errors까지, Kotlin 에러 처리 15년
haeti2
0
110
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
280
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
770
[PyCon KR 2026] More Variants, More Diversity for AI Accelerators
achimnol
0
130
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
160
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
110
Swift愛好会と私(ウホーイ) / Swift Fan Club and Uhooi
uhooi
0
100
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
200
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
140
typoなんかねぇよ
raspython3
0
640
ソフトウェアラスタライザ
fadis
1
760
FastAPI の並行処理モデルを完全に理解する
hoto17296
9
3.4k
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.3k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
230
A Tale of Four Properties
chriscoyier
163
24k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
500
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
YesSQL, Process and Tooling at Scale
rocio
174
15k
4 Signs Your Business is Dying
shpigford
187
23k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.3k
Amusing Abliteration
ianozsvald
1
280
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
30 Presentation Tips
portentint
PRO
1
380
Transcript
楽をするためのPHPDocと 配列型の落とし穴 2020.8.21 @PHP LT Fes
自己紹介 • 名前 ◦ 荒巻 拓哉 • 所属 ◦ 株式会社ラクス
▪ 配配メール というサービスの開発をしてます
PHPDoc、書いてますか?
https://github.com/symfony/symfony/blob/03155addd7c96a9455660b7d51d993cf4f8eb201/src/Symfony/Component/ HttpFoundation/InputBag.php
• コードを読む際に理解しやすい • ドキュメントを生成できる → phpDocumentor • IDEの補完が効きやすくなる → PhpStorm
• 静的解析ができる → PHPStan, Phan など 何のために書くの?
ドキュメント生成 https://github.com/PHPMailer/PHPMailer/blob/e7acd3d92fa02728c51bf64b90615bffc84815f0/src/PHPMailer.php
ドキュメント生成 http://phpmailer.github.io/PHPMailer/classes/PHPMailer.PHPMailer.PHPMailer.html#method_html2text
IDEで補完
静的解析 引数の型が違う、プロパティ・メソッドが存在しない、などを検出 DateTimeクラスにないメ ソッド 引数の型が違う
静的解析 PHPStan
静的解析 Phan
PHPDocの仕様? 各ツールでサポートする記法が少しずつ異なる PSR-5, PSR-19として標準化する動きはあるが、現時点ではまだ提案段階
PHPDocを書いてみる 題材:Userクラス ORマッパーのEntityクラスのイメージ
None
PHPDocを書いてみる PHPDocをちゃんと書いてるからヨシ! ……? → 全ユーザのユーザ名を表示する関数を書いてみる
補完が効かない
補完が効かない
静的解析でエラー検知できない PHPStan Phan
なんで? array型は中の要素の型はわからない → 補完も静的解析もできない
なんとかならないの? User[] と書きましょう プリミティブの配列でもOK • int[] • string[] • (User|string)[]※PhpStorm
2020.2時点で未対応
→
None
PHPStan Phan
その他の配列型の書き方 @return array<int> @return array<string, int> @return array{id: int, name:
string} 上記3つはPhpStorm 2020.2では未対応 (ただのarray扱いになる)
まとめ • PHPDocを書くと楽できる ◦ 自動でドキュメントを作ってくれる ◦ IDEで補完できる ◦ 静的解析ができる •
配列は要素の型も書く ◦ int[]形式 ◦ 連想配列はarray<string, int> か array{id: int}形式 ▪ ただしPhpStormは未対応 • PHPDocはしっかり書きましょう!!!
参考資料 • 2018年のPHPDoc事情とPSR-5 - Qiita https://qiita.com/tadsan/items/72b02339d12120ca37d7 • array shapes記法(Object-like arrays)と旧PSR-5記法で型をつける
- Qiita https://qiita.com/tadsan/items/bfa9465166c351da37e5 • PSR-19: PHPDoc tagsを予習してみよう - BASE開発チームブログ https://devblog.thebase.in/entry/2019/12/14/110000