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
460
Go言語低レイヤー入門 Hello world が 画面に表示されるまで / Introduction to low level programming in Go
dqneo
4
1.5k
入門Go言語仕様 / Go Specification Untyped Constants
dqneo
1
1.2k
入門Go言語仕様 Underlying Type / Go Language Underlying Type
dqneo
9
4.7k
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
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
520
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
170
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
C++26 エラー性動作
faithandbrave
2
730
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
720
生成AIのガバナンスの全体像と現実解
fnifni
1
180
KubeCon NA 2024 Recap / Running WebAssembly (Wasm) Workloads Side-by-Side with Container Workloads
z63d
1
240
Snykで始めるセキュリティ担当者とSREと開発者が楽になる脆弱性対応 / Getting started with Snyk Vulnerability Response
yamaguchitk333
2
180
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
150
ハイテク休憩
sat
PRO
2
140
MLOps の現場から
asei
6
640
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
65
11k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Building Adaptive Systems
keathley
38
2.3k
Typedesign – Prime Four
hannesfritz
40
2.4k
RailsConf 2023
tenderlove
29
940
Adopting Sorbet at Scale
ufuk
73
9.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
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