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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
むらおか
December 21, 2024
Technology
0
660
Opcodeを読んでいたら何故かphp-srcを読んでいた話
むらおか
December 21, 2024
Tweet
Share
Other Decks in Technology
See All in Technology
LLMに何を任せ、何を任せないか
cap120
10
6.1k
スケーリングを封じられたEC2を救いたい
senseofunity129
0
120
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
3
2k
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
4
1.3k
OCI技術資料 : ロード・バランサ 概要 - FLB・NLB共通
ocise
4
27k
OpenClawでPM業務を自動化
knishioka
1
320
AI時代のオンプレ-クラウドキャリアチェンジ考
yuu0w0yuu
0
610
Kiro Meetup #7 Kiro アップデート (2025/12/15〜2026/3/20)
katzueno
2
270
15年メンテしてきたdotfilesから開発トレンドを振り返る 2011 - 2026
giginet
PRO
1
200
Bill One 開発エンジニア 紹介資料
sansan33
PRO
5
18k
SSoT(Single Source of Truth)で「壊して再生」する設計
kawauso
2
400
夢の無限スパゲッティ製造機 #phperkaigi
o0h
PRO
0
390
Featured
See All Featured
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
160
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
230
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
320
Making Projects Easy
brettharned
120
6.6k
Mobile First: as difficult as doing things right
swwweet
225
10k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
190
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
First, design no harm
axbom
PRO
2
1.1k
30 Presentation Tips
portentint
PRO
1
260
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
170
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
280
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/ 参考資料