Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
XHPをはじめよう
Search
shirotter
April 20, 2018
Programming
0
270
XHPをはじめよう
Getting started with XHP
HHVM/Hack勉強会 vol.1 LT@2018/4/20
shirotter
April 20, 2018
Tweet
Share
Other Decks in Programming
See All in Programming
ゲームの物理 剛体編
fadis
0
370
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
310
ゆくKotlin くるRust
exoego
1
160
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
440
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
8
2.5k
Navigating Dependency Injection with Metro
l2hyunwoo
1
170
バックエンドエンジニアによる Amebaブログ K8s 基盤への CronJobの導入・運用経験
sunabig
0
170
GoLab2025 Recap
kuro_kurorrr
0
780
perlをWebAssembly上で動かすと何が嬉しいの??? / Where does Perl-on-Wasm actually make sense?
mackee
0
120
モデル駆動設計をやってみようワークショップ開催報告(Modeling Forum2025) / model driven design workshop report
haru860
0
280
AI Agent Dojo #4: watsonx Orchestrate ADK体験
oniak3ibm
PRO
0
110
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
0
260
Featured
See All Featured
What the history of the web can teach us about the future of AI
inesmontani
PRO
0
370
The Mindset for Success: Future Career Progression
greggifford
PRO
0
190
Into the Great Unknown - MozCon
thekraken
40
2.2k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
400
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.3k
4 Signs Your Business is Dying
shpigford
186
22k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
89
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
65
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
51
42k
Balancing Empowerment & Direction
lara
5
820
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
32
A better future with KSS
kneath
240
18k
Transcript
XHP をはじめよう HHVM/Hack 勉強会 vol.1 LT 枠@2018-4-20
自己紹介 Masaru Shiraishi istyle.inc 昔は海上自衛隊で船乗ってました
みなさんHack やってますか?
一緒にXHP も使ってますか?
XHP Facebook で開発されたPHP/Hack 拡張のHTML テンプレー トエンジンの ようなもの。 (XML ベー スの)HTML
構文がPHP/Hack の式として評価されるため、 HTML そのものをオブジェクトとして扱うことが出来たり、 再利用が可 能になります。 Hack の利点であるTypechecker での厳密なチェックが有効になるのも特 徴の一つです。 JavaScript ライブラリのReact のベー スにもなっています。
とりあえず見た方が早い!!
XHP を使わない実装 <?hh $href = urlencode("http://...."); echo "<a href='${href}'>Hello World</a>";
XHP を使った実装 <?hh $href = "http://...."; $xhp = <a href={$href}>Hello World<a>; echo $xhp;
XHP を使わない実装 <?hh $href = urlencode("http://...."); echo "<a href='${href}'>Hello World</a>";
XHP を使った実装 <?hh $href = "http://...."; $xhp = <a href={$href}>Hello World<a>; echo $xhp; ※ HTML が文字列ではないことに注目!!
XHP の特徴 HTML 要素を文字列ではなく、 オブジェクトとして扱える HTML やその属性のエスケー プ処理(XSS 対策) が自動
XML がベー スなので仕様が厳格 閉じタグ必須 HTML 要素のネストの誤りはエラー Hack ではTypechecker でのエラー 検出が可能
もっと知りたい方はドキュメントを見てください!! https://docs.hhvm.com/hack/XHP/introduction
今日はXHP をやってみたら見えてきた壁を さらっと紹介します
ひと手間が必要になる壁
そのままではCustome Elements が使えない XHP にはHTML の一般的なタグしか実装されていません。 そのため、Custom Elements を使うとコンパイルエラー になります。
<!-- "-" を含めなくてはならない命名規則がある --> <link rel="import" href="../custom-elements.html"> <custom-tag active></custom-tag> Custom Elements とは HTML の新しい型を定義できるWeb Components の機能。 “ “
解決するには 自分でXHP クラスを実装する必要があります。 <?hh // strict class :custom-tag extends :xhp:html-element
{ children empty; category %flow; attribute bool active; protected string $tagName = 'custom-tag'; } ※ 正確にはchildren empty; の要素は:xhp:html-singleton をextends するのが正しい
これからぶつかるかもしれない壁
デザイナー との協業が難しそう Hack のコー ドと混ざってしまう。 public function render(string $name): \XHPRoot
{ return ( <div class="hello-name"> <p>Hello {$name}</p> </div> ); } 社内ツー ルの実装なので今はまだデザイナー 不在でやってますが....
コンクリー トよりも堅い壁
何よりもXHP の情報が少ない!!
ほぼこの情報だけで頑張ってます... HHVM/Hack リファレンス https://docs.hhvm.com/hack/XHP/introduction XHP のソー スコー ド https://github.com/hhvm/xhp-lib XHP
Bootstrap のソー スコー ド https://github.com/fbsamples/xhp-bootstrap
ということで...
みなさん一緒にXHP やりましょう!!
ご静聴ありがとうございました