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
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
Haze - Real time background blurring
chrisbanes
1
510
From Translations to Multi Dimension Entities
alexanderschranz
2
130
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
920
The rollercoaster of releasing an Android, iOS, and macOS app with Kotlin Multiplatform | droidcon Italy
prof18
0
150
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
useSyncExternalStoreを使いまくる
ssssota
6
1k
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
200
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Faster Mobile Websites
deanohume
305
30k
What's in a price? How to price your products and services
michaelherold
243
12k
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)
୭͔͓ئ͍͠·͢ʂ