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
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
690
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
500
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.5k
アジャイルチームがらしさを発揮するための目標づくり / Making the goal and enabling the team
kakehashi
3
140
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
180
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
230
AI前提のサービス運用ってなんだろう?
ryuichi1208
8
1.4k
CDCL による厳密解法を採用した MILP ソルバー
imai448
3
140
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
SRE×AIOpsを始めよう!GuardDutyによるお手軽脅威検出
amixedcolor
0
170
OS 標準のデザインシステムを超えて - より柔軟な Flutter テーマ管理 | FlutterKaigi 2024
ronnnnn
0
200
Featured
See All Featured
Side Projects
sachag
452
42k
It's Worth the Effort
3n
183
27k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Teambox: Starting and Learning
jrom
133
8.8k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
GitHub's CSS Performance
jonrohan
1030
460k
We Have a Design System, Now What?
morganepeng
50
7.2k
Adopting Sorbet at Scale
ufuk
73
9.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Why Our Code Smells
bkeepers
PRO
334
57k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
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