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
690
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
水を運ぶ人としてのリーダーシップ
izumii19
4
1.2k
AIに障害切り分けを全部やってもらった。 。 。 。
estie
0
330
時期が悪い!それでもRaspberry Piを買って遊んで活用するには / 20260627-osc26do-rpi-jikigawarui
akkiesoft
1
960
從觀望到全公司落地:AI Agentic Coding 導入實戰 — 流程整合與安全治理
appleboy
1
490
RAGの精度向上とエージェント活用
kintotechdev
2
120
AIで政治は変わるのか? — 中高生と考えたAI時代の民主主義(東海高校サタデープログラム)
eitarosuda
0
360
AWS Blocks を触ってみた/first-tach-aws-blocks
fossamagna
2
110
“全部コピーしない”ファイルデータの活用 : — FSx for ONTAP × S3 Tables × Icebergで作るメタデータカタログ
yoshiki0705
0
250
Multi-Agent並列開発を 安全に回すための技術 / Technology for Safely Multi-Agent Parallel Development
tooppoo
0
250
グローバルチームと挑むプロダクト開発
sansantech
PRO
1
140
アラート調査向けAIエージェントの本番導入とその後/AI Agents for Alert Investigation: Production Deployment and After
taddy_919
1
320
小さいから、全部わかる。— 常駐AI "xangi" のすすめ
sugupoko
0
220
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
630
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Bash Introduction
62gerente
615
220k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
400
Faster Mobile Websites
deanohume
310
32k
Automating Front-end Workflow
addyosmani
1370
210k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
180
Mobile First: as difficult as doing things right
swwweet
225
10k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
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/ 参考資料