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
self in return type declaration
Search
DQNEO
June 27, 2018
Technology
1
170
self in return type declaration
PHPの戻り値型宣言でselfを使ってみよう
DQNEO
June 27, 2018
Tweet
Share
More Decks by DQNEO
See All by DQNEO
英和辞書付きGo言語仕様書 / Word Wise Go Spec
dqneo
1
450
Go言語低レイヤー入門 Hello world が 画面に表示されるまで / Introduction to low level programming in Go
dqneo
3
1.5k
入門Go言語仕様 / Go Specification Untyped Constants
dqneo
1
1.2k
入門Go言語仕様 Underlying Type / Go Language Underlying Type
dqneo
9
4.6k
How to write a self hosted Go compiler from scratch (Gophercon 2020)
dqneo
3
1.5k
もっと気軽にOSSに Pull Requestを出そう!/ Let's make a PR to OSS more easily
dqneo
6
8.1k
Goコンパイラをゼロから作ってセルフホスト達成するまで / How I wrote a self hosted Go compiler from scratch
dqneo
15
14k
コンパイラをつくってみよう / How to make a compiler
dqneo
9
11k
コンパイラ作りの魅力を語る / Making compilers is fun
dqneo
10
8.3k
Other Decks in Technology
See All in Technology
Lexical Analysis
shigashiyama
1
150
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
テストコード品質を高めるためにMutation Testingライブラリ・Strykerを実戦導入してみた話
ysknsid25
7
2.6k
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
730
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
520
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
DMARC 対応の話 - MIXI CTO オフィスアワー #04
bbqallstars
1
160
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
940
Engineer Career Talk
lycorp_recruit_jp
0
140
Featured
See All Featured
Speed Design
sergeychernyshev
24
610
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
The Language of Interfaces
destraynor
154
24k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Code Reviewing Like a Champion
maltzj
520
39k
Music & Morning Musume
bryan
46
6.2k
BBQ
matthewcrist
85
9.3k
How GitHub (no longer) Works
holman
310
140k
The World Runs on Bad Software
bkeepers
PRO
65
11k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
A designer walks into a library…
pauljervisheath
203
24k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Transcript
!%2/&0 Ͳ͖ΎͶ͓ BU.FSDBSJ QIQTUVEZ lTFMGzJO 3FUVSO5ZQF%FDMBSBUJPO
(JUຊͷम͠·ͨ͠
3FUVSOUZQFEFDMBSBUJPO Γͷܕએݴ ͬͯ·͔͢ʁ
function foo(): int { } Γͷܕએݴͱʁ ͜Μͳͭ
ྫɿࣗΛฦ͢ϝιου class A { public function getMe(): A { return
$this; } }
࣮TFMGͱॻ͚Δ class A { public function getMe(): self { return
$this; } }
ΜΓʂʂ
ҙ֎ͱΒͳ͍ਓ ଟ͍ҹ
ެࣜυΩϡϝϯτʹ ͳ͔ͥTFMGʹ͍ͭͯ ݴٴͳ͠ IUUQQIQOFUNBOVBMFOGVODUJPOTSFUVSOJOH WBMVFTQIQGVODUJPOTSFUVSOJOHWBMVFTUZQFEFDMBSBUJPO
3'$ͷԼͷํʹখ͞ʙ͘ ॻ͍ͯ͋Δ IUUQTXJLJQIQOFUSGDSFUVSO@UZQFT
ܧঝ͢ΔͱͲ͏ͳΔʁ class A { public function getMe(): self { return
$this; } } class B extends A {} $b = new B(); $b->getMe(); // ?
ਖ਼ղ#ͷΠϯελϯε͕ฦΔ class A { public function getMe(): self { return
$this; } } class B extends A {} $b = new B(); $b->getMe(); // instance of B
UIJTɺ#ͷίϯςΩε τ͔ΒݺΕΔͱ#ͷΠ ϯελϯεΛࢦ͢ͷͰɻ
ࠨͷίʔυӈͷίʔυͱՁ class A { public function getMe(): A { return
$this; } } class B extends A {} $b = new B(); $b->getMe(); // B class A { public function getMe(): self { return $this; } } class B extends A {} $b = new B(); $b->getMe(); // B
Γͷܕɺ ࣮ߦ࣌ʹSFUVSO͞Εͨࡍʹ JOTUBODFPG తͳͷͰ ͰνΣοΫ͞ΕΔ
͜ͷ߹Ͳ͏ͳΔʁ class A { public function getMe(): self { return
$this; } } class B extends A { public function getMe(): self { return $this; } }
'BUBMFSSPS ࣮ߦ࣌ίϯύΠϧΤϥʔ 1)1'BUBMFSSPS %FDMBSBUJPOPG#HFU.F #NVTUCFDPNQBUJCMFXJUI "HFU.F "
͜Ε͕μϝͳͷͱಉ͡ γάωνϟͷෆҰக class A { public function getMe(): A
… } class B extends A { public function getMe(): B … }
͜͏͢Ε͓̺ class A { public function getMe(): self { return
$this; } } class B extends A { public function getMe(): parent { return $this; } }
͜Ε͕0,ͳͷͱಉ͡ class A { public function getMe(): A … }
class B extends A { public function getMe(): A … }
༨ஊɿ͜Εকདྷͷ1)1Ͱ ՄೳʹͳΔ͔͠Εͳ͍ɻ Γͷڞม class A { public function getMe():
A } class B extends A { public function getMe(): B … } IUUQTXJLJQIQOFUSGDDPWBSJBOUSFUVSOTBOE DPOUSBWBSJBOUQBSBNFUFST
ͪͳΈʹܕ໊ͷͱ͜Ζʹ TUBUJDෆՄɻ class A { public function getMe(): static …
}
·ͱΊ w ΓܕએݴͰTFMG QBSFOU ͕͑Δ w ཚ༻͢ΔͱΘ͔Γʹ͘͘ͳΔ ͷͰదࡐదॴͰ w ʮJOTUBODFPGνΣοΫʯͩͱ
ࢥ͓̺͑
༨ஊɿϝιουͷҾͰ͑Δ class A { public function setMe(self $self) { $this->self
= $self; } } class B extends A { public function setMe(parent $self) { $this->self = $self; } }
͝ਗ਼ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ NN