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
Reflection を使いこなして、 オブジェクトを型安全に マッピングしよう!
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Masaru Yamagishi
September 24, 2022
Programming
1k
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
Transcript
15 slides
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 まとめ
More Decks by Masaru Yamagishi
See All by Masaru Yamagishi
Babylon.js 勉強会 vol.4 JAPAN 活動紹介
myamagishi
0
190
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
1.2k
3D ブラウザゲーム開発を始めたい人のために準備している話
myamagishi
1
260
「DI」と仲良くなる
myamagishi
6
3.8k
大解剖!amphpを使って非同期 PHP を実現しよう!
myamagishi
1
4.3k
PHP で負荷試験のシナリオを書きたい!ので amphp を使って自作した件
myamagishi
2
1.3k
秒間 10,000 リクエストを "簡単に"いなすゲームサーバーを Laravel で作る設計
myamagishi
19
17k
xR グラスが普及した新時代を妄想する - XRKaigi 2022
myamagishi
0
320
世界最速? で PHP8 Native Framework 作った
myamagishi
1
880
Other Decks in Programming
See All in Programming
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
200
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
170
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
210
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
150
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
290
LLM 101
dalinaum
0
490
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
310
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
340
小さなアプリを作って公開するまで
onozaty
0
170
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
12k
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
0
160
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
230
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
The browser strikes back
jonoalderson
0
1.9k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
680
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Heart Work Chapter 1 - Part 1
lfama
PRO
11
37k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Thoughts on Productivity
jonyablonski
76
5.5k
How to train your dragon (web standard)
notwaldorf
96
6.9k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
400
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
1k