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
Reflection を使いこなして、 オブジェクトを型安全に マッピングしよう!
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Masaru Yamagishi
September 24, 2022
Programming
980
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Reflection を使いこなして、 オブジェクトを型安全に マッピングしよう!
PHP Conference Japan 2022 LT Slide
Masaru Yamagishi
September 24, 2022
More Decks by Masaru Yamagishi
See All by Masaru Yamagishi
Babylon.js 勉強会 vol.4 JAPAN 活動紹介
myamagishi
0
150
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
1.1k
3D ブラウザゲーム開発を始めたい人のために準備している話
myamagishi
1
230
「DI」と仲良くなる
myamagishi
6
3.7k
大解剖!amphpを使って非同期 PHP を実現しよう!
myamagishi
1
4.1k
PHP で負荷試験のシナリオを書きたい!ので amphp を使って自作した件
myamagishi
2
1.2k
秒間 10,000 リクエストを "簡単に"いなすゲームサーバーを Laravel で作る設計
myamagishi
19
16k
xR グラスが普及した新時代を妄想する - XRKaigi 2022
myamagishi
0
310
世界最速? で PHP8 Native Framework 作った
myamagishi
1
870
Other Decks in Programming
See All in Programming
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
200
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
490
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
220
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
110
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
480
フィードバックで育てるAI開発
kotaminato
1
100
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
260
関数型プログラミングのメリットって何だろう?
wanko_it
0
140
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
13
2.6k
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.9k
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
110
Featured
See All Featured
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
340
Information Architects: The Missing Link in Design Systems
soysaucechin
0
1k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
180
The Limits of Empathy - UXLibs8
cassininazir
1
390
エンジニアに許された特別な時間の終わり
watany
107
250k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
960
Ruling the World: When Life Gets Gamed
codingconduct
0
270
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
280
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Docker and Python
trallard
47
3.9k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Why Our Code Smells
bkeepers
PRO
340
58k
Transcript
Reflection を使いこなして、 オブジェクトを型安全に マッピングしよう! PHP Conference Japan 2022 - やまゆ
https://fortee.jp/phpcon-2022/proposal/51f66d0e-5bae-4902-bb63-89700407204a
やまゆ - 札幌の PHPer(㈱インフィニットループ) - Babylon.js 勉強会 - 好き: 🍶、☕、🐇、デレマス、カピバラ
- 最近: 壱百満天原サロメ、スプラトゥーン3
None
何故 LT 枠で 応募した自分?
Reflection
Reflection とは? - ランタイム等で「コードそのもの」の構造を取得・改変する技術 - 引数の型や名前を取得したり、 private メソッドを無理やり外で呼べる (危険) -
メタプログラミングとも呼ばれる - ビジネスロジックでは使われることはほぼないが、ライブラリやFWでは重要 - PHP 8 Attribute も Reflection 経由で取得できる - PHP は(大雑把に言うと)コンパイルしないので、 容易に Reflection 情報を取得できる
例) json をクラスに変換したい
例) json をクラスに変換したい
こういう IF だと良さそう
こういう IF だと良さそう psalm でジェネリクス型を疑似表現! クラス名文字列とIDを指定して変換
実装例
実装例
実装例 該当クラスのメタ情報を取得 コンストラクタパラメータ一覧取得 null は優先して処理 ここでインスタンス化
実装例
- PHP では簡単に Reflection を扱える - PHP 8.1~ の型に優しい実装 -
データのマッピングだけでなく、コード自動生成などにも寄与する - 社内ライブラリとして共有されていることもありそう - ビジネスロジックを楽にする仕組みとして入れると良い - Reflection は いいぞ。 https://gist.github.com/il-m-yamagishi/b845406086fdef32a5f794ff02eba30a Reflection まとめ