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
mixin実装の現状と課題
Search
Ryusuke SEKIYAMA
March 15, 2014
Programming
2
2.9k
mixin実装の現状と課題
第五回闇PHP勉強会のミックスインについてLTしたスライドです
Ryusuke SEKIYAMA
March 15, 2014
Tweet
Share
More Decks by Ryusuke SEKIYAMA
See All by Ryusuke SEKIYAMA
php_mecabをFFIで実装してみよう
rsky
0
610
Other Decks in Programming
See All in Programming
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
630
ヤプリ新卒SREの オンボーディング
masaki12
0
130
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
Contemporary Test Cases
maaretp
0
140
cmp.Or に感動した
otakakot
3
200
最新TCAキャッチアップ
0si43
0
190
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Realtime API 入門
riofujimon
0
150
Jakarta EE meets AI
ivargrimstad
0
620
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
133
8.9k
The Language of Interfaces
destraynor
154
24k
What's new in Ruby 2.0
geeforr
343
31k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Scaling GitHub
holman
458
140k
Six Lessons from altMBA
skipperchong
27
3.5k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
Transcript
mixin実装�の現状と課題 @rsky 2014-03-15 第五回闇PHP勉強会
PHP (>= 5.4) ͰͷTraits TraitͰܕʢΫϥεͷܧ ঝؔʣʹӨڹΛ༩͑ ͣʹػೳΛ࠶ར༻Ͱ͖ ΔΑ͏ʹͳͬͨɻ Ϋϥεએݴ࣌ʹ੩తʹ هड़͢Δɻ
<?php trait FooFighter { function foo() { echo “FOO\n”; } } ! class A { use FooFighter; } ! class B { use FooFighter; }
ҰํɺScalaͰ ଞͷΫϥεΛܧঝ͠ͳ͍ ͱ͖extendsͰϛο ΫεΠϯɻ ଞͷΫϥεΛܧঝ͢Δͱ ͖withͰϛοΫεΠ ϯɻ ΠϯελϯεԽ࣌ʹϛο ΫεΠϯͰ͖Δɻ trait
FooFighter { def foo = println(“FOO”) } ! class A extends FooFighter ! class B extends C with FooFighter ! val c = new C() with FooFighter
lΠϯελϯεԽ࣌ʹϛοΫεΠϯͰ͖Δz
1)1Ͱ͜ΕΓ͍ͨʂ
Ͱ͍͠ΜͰ͠ΐ͏
Ͱ͖ͨʂ http://blog.r-sky.jp/post/38388457154/qiq-reborn https://github.com/rsky/php-src/tree/scala-like-mixin
Ͱ͖ͨ͜ͱ ΠϯελϯεԽ࣌ʹ use Traitͯ͠Ϋϥε Λੜ͢Δߏจɻ Ϋϥε໊ͷΘΓʹม ར༻Մೳɻ →factoryύλʔϯ͖ <?php trait
FooFighter { function foo() { echo “FOO\n”; } } ! class A {} ! (new A use FooFighter)- >foo(); ! $x = ‘FooFighter’; (new A use $x)->foo();
Ͱ͖͍ͯͳ͍͜ͱ Precedenceʢ༏ઌॱҐ ผ໊ͷఆٛʣ <?php trait FooFighter { function foo() {
echo “FOO\n”; } } ! class A {} ! (new A use FooFighter { FooFighter::foo as bar; })->bar();
Πέͯͳ͍͜ͱ new Class use (Trait1, Trait2, …) ($arg1, $arg2, …)
ܗࣜͷͨΊɺτϨΠτͱί ϯετϥΫλҾ͕ฆΒΘ͍͠ɻ →࠷৽൛ͰτϨΠτ͕1ͭͰׅހඞਢʹͨ͠ <?php $ab = new A use B ($arg1, $arg2); $abc = new A use (A, B) ($arg1, $arg2);
͜͏͍ͨ͠ʂ useεςʔτϝϯτΛίϯετϥΫλҾͷޙʹɻ Precedenceॻ͚Δɻ PrecedenceͰมͰΫϥεղܾͰ͖Δɻ <?php $ab = new A ($arg1,
$arg2) use B; $abc = new A ($arg1, $arg2) use ($b, $c) { $b::foo insteadof $a; $c::foo as bar; };
͜Ε͋Γʁ τϨΠτͷϦετΛׅހͰׅ͍ͬͯΔͷߏจ্ ͷ༏ઌॱҐͷͨΊͳͷͰɺScalaͷΑ͏ʹෳͷ useεςʔτϝϯτΛྻڍ͢Δख͋Δɻ <?php $abc = new A ($arg1,
$arg2) use B use C;
ٕज़త՝ yaccతʹໃ६͕ͳ͍จ๏ఆٛ·Ͱ ʢखݩͷόʔδϣϯͰʣͰ͖͍ͯΔɻ ҾϦετ͕࢝·ΔΑΓલʹΠϯελϯεԽ͢Δ Ϋϥε͕֬ఆ͍ͯ͠ͳ͍ͱ͍͚ͳ੍͍ݶ͕͋Δɻ <?php $abc = new A
($arg1, $arg2) use (B, C);
ղܾҊA ຊ࣭తղܾʁ ਖ਼ɺ͍͠ Zend EngineΛ৽͍͠จ๏ͷͨΊʹΰϦΰϦॻ͖͑Δ
ղܾҊB new A($arg) use(B, C) ↓ new A use (B,
C) ($arg) ϓϦϓϩηοαΛ͔·ͯ͠ਓʹ͍͞͠ίʔυΛ! ػցʹ͍͞͠ίʔυʹܗ͔ͯ͠ΒίϯύΠϧ ݸਓతʹͬͪ͜ͷํ͕Έ PHP: Hypertext Preprocessor
ղܾҊC (ABં?) ίϯύΠϥΛ͍ͬͯ͘͡op_arrayΛฒͼସ͑Δ ίʔυ্Ͱ͜͏ new A($arg) use(B, C) ίϯύΠϧ͞ΕͨόΠτίʔυͰ͜ΕͱՁ new
A use(B, C)($arg)
୭͔͓ئ͍͠·͢ʂ