Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
楽をするためのPHPDocと配列型の落とし穴 / PHPDoc and pitfalls of...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
Railsバージョンを4倍にした話
optim
0
900
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
530
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
110
Modernizing iOS Apps
seyfoyun
0
150
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
250
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
3
1.3k
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
240
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
240
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
160
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
140
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
350
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
250
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
BBQ
matthewcrist
90
10k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
600
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
960
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
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