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
むらおか
December 21, 2024
Technology
680
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Opcodeを読んでいたら何故かphp-srcを読んでいた話
むらおか
December 21, 2024
Other Decks in Technology
See All in Technology
"何を作るか"を任される エンジニアは、どう育つのか
yutaokafuji
1
670
小さくはじめるSLI/SLO ~育てながら組織に定着させる実践知~ / Starting Small with SLI/SLOs: Building Adoption Through Continuous Growth
nari_ex
7
1.9k
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
2k
On-behalf-of Token exchange with AgentCore Identity
hironobuiga
2
170
人材育成分科会.pdf
_awache
3
210
エンジニアリング戦略の作り方 / Crafting Engineering Strategy
iwashi86
21
6.8k
2026TECHFRESH畢業分享會 - 原生還是跨平台? App 開發踩坑實錄
line_developers_tw
PRO
0
970
LLMにもCAP定理があるという話
harukasakihara
0
330
2026 TECHFRESH 畢業分享會 - AI-Native 重塑軟體工程與虛擬講師
line_developers_tw
PRO
0
960
アンオフィシャルな、オフィシャルからのお願い
wyamazak_devrel
0
100
日本 Fintech 未来予測レポート 2027〜2028年(オリジナル版)
8maki
0
2.1k
2026.06.13_AI時代に事業会社が「SIer出身エンジニア」を求める理由 / Why Businesses Seek Engineers with a System Integrator Background in the AI Era
jumtech
0
1.1k
Featured
See All Featured
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
200
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
840
HDC tutorial
michielstock
2
710
Rails Girls Zürich Keynote
gr2m
96
14k
Statistics for Hackers
jakevdp
799
230k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
22k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
610
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
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/ 参考資料