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
Opcodeを読んでいたら何故かphp-srcを読んでいた話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
むらおか
December 21, 2024
Technology
670
0
Share
Opcodeを読んでいたら何故かphp-srcを読んでいた話
むらおか
December 21, 2024
Other Decks in Technology
See All in Technology
React Compiler導入の効果と運用の工夫
kakehashi
PRO
3
280
How to learn AWS Well-Architected with AWS BuilderCards: Security Edition
coosuke
PRO
0
150
みんなの考えた最強のデータ基盤アーキテクチャ'26前期〜前夜祭〜ルーキーズ_資料_遠藤な
endonanana
0
460
「強制アップデート」か「チームの自律」か?エンタープライズが辿り着いたプラットフォームのハイブリッド運用/cloudnative-kaigi-hybrid-platform-operations
mhrtech
0
210
AWS運用におけるAI Agent活用術 / JAWS-UG 神戸 #11 LT大会
genda
1
300
React Compiler導入から21ヶ月、いま始めるならこうやる
astatsuya
2
270
TSKaigi 2026 - enumよ、さようなら
teamlab
PRO
1
140
Cortex(Code) を ML モデルの 精度改善サイクルに組み込む.pdf
oimo23
0
220
クラウドネイティブ DB はいかにして制約を 克服したか? 〜進化歴史から紐解く、スケーラブルアーキテクチャ設計指針〜
hacomono
PRO
6
1.1k
TypeScriptで実現する既存APIを活用したリモートMCPサーバー構築 / TSKaigi 2026
soarteclab
0
110
AWS WAFの運用を地道に改善し、自社で運用可能にするプラクティス
andpad
1
540
GitHub Copilot CLI で考える複数エージェント設計
tomokusaba
0
120
Featured
See All Featured
Code Review Best Practice
trishagee
74
20k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
250
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.2k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
190
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
180
4 Signs Your Business is Dying
shpigford
187
22k
Abbi's Birthday
coloredviolet
2
7.6k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
330
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
150
Building an army of robots
kneath
306
46k
WENDY [Excerpt]
tessaabrams
10
37k
Transcript
Opcodeを読んでいたら 何故かphp-srcを読んでいた話 むらおか @muraSHOTARO PHP Conference Japan 2024
intの型キャストとintval関数 • (int) “1234” と intval(“1234”) • 文字列を整数にする
intの型キャストとintval関数 • (int) “1234” と intval(“1234”) • 文字列を整数にする なにが違う?
php-srcを読んでみよう!
C言語わからない。。。
php-srcの前にOpcodeを読むと良いらしい • OpcodeはPHPファイルを解析して生成される中間コード • PHP実行時に内容を出力することができる
Opcodeを読んでみよう!
intval (int)
intval (int)
関数の呼び出しの場合 • INIT_FCALL • DO_ICALL
• いくつかの関数がOpcodeのコンパイル時に最適化されるようになった ◦ intvalもそのうちの1つ (>=7.1.0) • Opcodeのコンパイルは zend_compile_* 関数で行われる ◦
https://wiki.php.net/rfc/abstract_syntax_tree#compiler_implementation AST導入とOpcodeの最適化
• いくつかの関数がOpcodeのコンパイル時に最適化されるようになった ◦ intvalもそのうちの1つ (>=7.1.0) • Opcodeのコンパイルは zend_compile_* 関数で行われる ◦
https://wiki.php.net/rfc/abstract_syntax_tree#compiler_implementation AST導入とOpcodeの最適化 zend_compile_* を探そう!
php-srcを読んでみよう!
zend_compile.c を読む • zend_try_compile_special_func ◦ intvalは特別な関数 https://github.com/php/php-src/blob/php-7.1.0/Zend/zend_compile.c#L3664
zend_compile.c を読む • zend_compile_func_cast ◦ ZEND_CASTにコンパイルされる https://github.com/php/php-src/blob/php-7.1.0/Zend/zend_compile.c#L3395
intval (int) Opcodeが 最適化されてる
• Opcodeリーディングはphp-srcを読む糸口になる • C言語を読むのに抵抗がある人でもOpcodeなら読みやすいかも? まとめ
• Opcodeリーディングはphp-srcを読む糸口になる • C言語を読むのに抵抗がある人でもOpcodeなら読みやすいかも? まとめ Opcodeから始めよう!
ありがとうございました!
https://wiki.php.net/rfc/abstract_syntax_tree https://qiita.com/tadsan/items/d11229761504c8a1ca81 https://speakerdeck.com/yasuaki640/phpnoopcodewo-du-ndemiyou https://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/ 参考資料