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
600
Other Decks in Programming
See All in Programming
レガシーな Android アプリのリアーキテクチャ戦略
oidy
1
170
のびしろを広げる巻き込まれ力:偶然を活かすキャリアの作り方/oso2024
takahashiikki
1
410
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
430
色々なIaCツールを実際に触って比較してみる
iriikeita
0
270
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
480
Java ジェネリクス入門 2024
nagise
0
600
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2.2k
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
3.1k
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
260
役立つログに取り組もう
irof
26
8.7k
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.3k
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
340
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
A better future with KSS
kneath
238
17k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
A Philosophy of Restraint
colly
203
16k
GraphQLの誤解/rethinking-graphql
sonatard
66
9.9k
Being A Developer After 40
akosma
86
590k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
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)
୭͔͓ئ͍͠·͢ʂ