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
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
190
Arm移行タイムアタック
qnighy
0
310
距離関数を極める! / SESSIONS 2024
gam0022
0
280
Outline View in SwiftUI
1024jp
1
320
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
Quine, Polyglot, 良いコード
qnighy
4
640
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
327
21k
Git: the NoSQL Database
bkeepers
PRO
427
64k
It's Worth the Effort
3n
183
27k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Music & Morning Musume
bryan
46
6.2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Being A Developer After 40
akosma
86
590k
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)
୭͔͓ئ͍͠·͢ʂ