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
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
440
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.7k
カスタムしながら理解するGraphQL Connection
yanagii
1
1.2k
Identifying User Idenity
moro
6
7.8k
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
16
4k
現場で役立つモデリング 超入門
masuda220
PRO
13
2.9k
Vitest Browser Mode への期待 / Vitest Browser Mode
odanado
PRO
2
1.7k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
550
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
390
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
140
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
360
gopls を改造したら開発生産性が高まった
satorunooshie
8
240
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
45
6.6k
Building Better People: How to give real-time feedback that sticks.
wjessup
363
19k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
32
1.8k
Docker and Python
trallard
40
3.1k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
Teambox: Starting and Learning
jrom
132
8.7k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
How GitHub (no longer) Works
holman
311
140k
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)
୭͔͓ئ͍͠·͢ʂ