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
440
Go言語低レイヤー入門 Hello world が 画面に表示されるまで / Introduction to low level programming in Go
dqneo
3
1.4k
入門Go言語仕様 / Go Specification Untyped Constants
dqneo
1
1.1k
入門Go言語仕様 Underlying Type / Go Language Underlying Type
dqneo
9
4.5k
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
8k
Goコンパイラをゼロから作ってセルフホスト達成するまで / How I wrote a self hosted Go compiler from scratch
dqneo
14
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
【shownet.conf_】ローカル5Gを活用したウォーキングツアーの体感向上
shownet
PRO
0
330
XPを始める新人に伝えたい近道の鍵
nakasho
1
310
Azure App Service on Linux の Sidecar に Phi-3 を配置してインテリジェントなアプリケーションを作ってみよう/jazug-anniv14
thara0402
0
370
エムスリーマネジメントチーム紹介資料 / Introduction of M3 Management Team
m3_engineering
0
270
AWSの初級者向けAI・ML資格『AWS Certified AI Practitioner』の傾向と対策/So You Want To Pass AWS Certified AI Practitioner
quiver
0
150
【shownet.conf_】放送局とShowNetが共創する、未来の放送システム ~Media over IP 特別企画の裏側~
shownet
PRO
0
340
AWS Lambdaで実現するスケーラブルで低コストなWebサービス構築/YAPC::Hakodate2024
fujiwara3
7
3.1k
Oracle Database 23ai 新機能#4 Rolling Maintenance
oracle4engineer
PRO
0
120
Case Study: Concurrent Counting
ennael
PRO
0
100
Oracle Database 23ai 新機能#4 Real Application Clusters
oracle4engineer
PRO
0
150
エンジニアは伝え方が9割/90% of what engineers need is communication skills
ykanoh
3
270
【shownet.conf_】トポロジ図の歩き方
shownet
PRO
0
490
Featured
See All Featured
Thoughts on Productivity
jonyablonski
67
4.2k
How To Stay Up To Date on Web Technology
chriscoyier
787
250k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
Unsuck your backbone
ammeep
668
57k
Speed Design
sergeychernyshev
22
480
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Code Reviewing Like a Champion
maltzj
519
39k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
For a Future-Friendly Web
brad_frost
174
9.3k
Facilitating Awesome Meetings
lara
49
6k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
130k
Why Our Code Smells
bkeepers
PRO
334
57k
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