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
Storage Browser for Amazon S3
miu_crescent
1
180
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
160
podman_update_2024-12
orimanabu
1
270
統計データで2024年の クラウド・インフラ動向を眺める
ysknsid25
2
850
大幅アップデートされたRagas v0.2をキャッチアップ
os1ma
2
540
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
240
.NET 9 のパフォーマンス改善
nenonaninu
0
950
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
170
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
AWS re:Invent 2024で発表された コードを書く開発者向け機能について
maruto
0
190
生成AIのガバナンスの全体像と現実解
fnifni
1
190
UI State設計とテスト方針
rmakiyama
2
600
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Designing for humans not robots
tammielis
250
25k
A better future with KSS
kneath
238
17k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
How GitHub (no longer) Works
holman
311
140k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Docker and Python
trallard
42
3.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
What's in a price? How to price your products and services
michaelherold
243
12k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
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