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
PHP7.2で始める型宣言 // Type declaration with PHP 7.2
Search
Yoshihide TANIGUCHI
December 06, 2017
Programming
0
280
PHP7.2で始める型宣言 // Type declaration with PHP 7.2
2017/12/06 社内テックミーティング
Yoshihide TANIGUCHI
December 06, 2017
Tweet
Share
More Decks by Yoshihide TANIGUCHI
See All by Yoshihide TANIGUCHI
スタディサプリ/Quipper オンラインミートアップ #1(Webエンジニア) / 新規サービス開発チームの紹介 / Studysapuri online meetup #1
ravelll
0
2.3k
Raspberry Pi と Netatmo と少しの ruby で作る二酸化炭素濃度モニター君
ravelll
0
72
Ruby の静的型チェックの話
ravelll
0
78
Quipperian and VimConf2019
ravelll
1
5.6k
さくらのフロントエンド さくらの Vue.js // vue.js in SAKURA
ravelll
3
4.2k
ISUCONのすゝめ // Shall we ISUCON ?
ravelll
0
110
オブジェクト指向設計とデザインパターンの基礎 / Basics of object oriented design and design pattern
ravelll
0
700
1人から始める大規模Webアプリケーションの言語バージョンアップ / Upgrade PHP in a large application
ravelll
0
130
PHP 5.4 ~ 5.6 での追加機能のおさらいとバージョンアップへの誘い / Re-introduce PHP5.4~5.6 and invitation for upgrading
ravelll
0
91
Other Decks in Programming
See All in Programming
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
990
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
200
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
150
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
170
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
1k
歴史と現在から考えるスケーラブルなソフトウェア開発のプラクティス
i10416
0
140
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
290
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
290
良いユニットテストを書こう
mototakatsu
9
3.2k
Beyond ORM
77web
9
1.2k
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
350
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
750
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Designing for humans not robots
tammielis
250
25k
What's in a price? How to price your products and services
michaelherold
244
12k
YesSQL, Process and Tooling at Scale
rocio
170
14k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
How to Ace a Technical Interview
jacobian
276
23k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
530
Making the Leap to Tech Lead
cromwellryan
133
9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.1k
A Tale of Four Properties
chriscoyier
157
23k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
Transcript
1)1Ͱ࢝ΊΔܕએݴ &$5&$).&&5*/( !SBWFMMM
w ࣾͰ1)1Yͷػӡ͕ͲΜͲΜߴ·͍ͬͯ·͢ w ॲཧ͕ߴԽ͢Δ͚ͩͰͳ͘ɺͰ͖Δ͜ͱ͕૿͑·͢ w ͦͷதͰɺ1)1͔Β͖߹͍ํ͕มΘΔɾม͑Δ ͱྑ͍֓೦͕͋Γ·͢ w ߴ࣭ͳιϑτΣΞΛ࡞Γ͍ͨɺ1)1Ͱɻ
w ൃදͷ༰Λ͖ͬͪΓ֮͑Δඞཁͳ͍Ͱ͢ w ͜ͷʹ͍Δਓ͕কདྷ1)1ͷίʔυΛॻ͘ͱ͖ʹ ʮͦ͏͍͍͑͋͋͏ػೳ͕͋ͬͨؾ͕͢Δʯͱ ࢥ͍ग़ͯ͠Β͑Εे w ػೳͷ͍ํௐΒΕΔ͚Ͳ ػೳͷଘࡏೳಈతʹͬͯΔਓҎ֎ؾ͚ͮͳ͍
ࠓճઆ໌͢Δػೳɿܕએݴ
class Calculator { public static function pow3(int $n) : int
{ return $n ** 3; } } try { print Calculator::pow3(3); } catch (TypeError $e) { print "TypeError!"; } // => 27
ܕએݴ w ݹ͘λΠϓώϯςΟϯάͱ w ϝιουؔͷҾɾฦΓͷܕΛࢦఆ͢Δػೳ w 1)1͔Βଘࡏ͕ͨ͠ɺόʔδϣϯ্͕͕ΔʹͭΕɺ ΑΓଟ͘ͷܕ͕ࢦఆͰ͖ΔΑ͏ʹͳͬͨ w ֤όʔδϣϯͰࢦఆͰ͖Δܕʹ͍ͭͯ
υΩϡϝϯτ˞ʹॻ͍ͯ͋Γ·͢ ˞IUUQQIQOFUNBOVBMKBGVODUJPOTBSHVNFOUTQIQGVODUJPOTBSHVNFOUTUZQFEFDMBSBUJPO
ܕએݴͷແ͍࣮
class Calculator { public static function pow3($n) { return $n
** 3; } } print Calculator::pow3(3); // => 27
class Calculator { public static function pow3($n) { return $n
** 3; } } print Calculator::pow3("string"); // ???
class Calculator { public static function pow3($n) { return $n
** 3; } } print Calculator::pow3("string"); // => 0
w จࣈྻΛೖྗͨ͠߹ w ֘ͷϝιουͰΤϥʔʹͳΒͳ͍͕ɺ ͦͦ·͍͠ೖྗͰͳ͘ɺ݁Ռͷແҙຯ w ଓ͘ॲཧͰΤϥʔʹͳͬͨͱ͖ɺσόοά͕ࠔʹ w (BSCBHFJO HBSCBHFPVU
w ແҙຯͳೖྗ͔Βແҙຯͳ݁Ռ͕ಘΒΕΔ
ҾΛνΣοΫͯ͠ΈΔ
class CalculateException extends Exception {} class Calculator { public static
function pow3($n) { if (!is_int($n)) { throw new CalculateException; } return $n ** 3; } } try { print Calculator::pow3('string'); } catch (CalculateException $e) { print 'Exception!!!'; } // => 'Exception!!!'
w Ҿ૿͑ͨͱ͖ʹՄಡੑ͕Լ͕Δ w &YDFQUJPO༧͞ΕΔΤϥʔͷରॲ๏Ͱ͋ͬͯɺ ͋ͬͯͳΒͳ͍ࣄ ࠓճͷ߹ͩͱจࣈྻΛೖྗ͢Δ͜ͱ ͷରॲ๏Ͱͳ͍ͷͰʁ w ෆਖ਼ͳೖྗͦͦड͚͚ͳ͍Α͏ʹ͍ͨ͠
ͦ͜Ͱܕએݴ
class Calculator { public static function pow3(int $n) : int
{ return $n ** 3; } } try { print Calculator::pow3(3); } catch (TypeError $e) { print "TypeError!"; } // => 27
class Calculator { public static function pow3(int $n) : int
{ return $n ** 3; } } try { print Calculator::pow3("string"); } catch (TypeError $e) { print "TypeError!"; } // => "TypeError!"
class Calculator { public static function pow3(int $n) : int
{ return $n ** 3; } } try { print Calculator::pow3("3"); } catch (TypeError $e) { print "TypeError!"; } // ???
class Calculator { public static function pow3(int $n) : int
{ return $n ** 3; } } try { print Calculator::pow3("3"); } catch (TypeError $e) { print "TypeError!"; } // => 27
declare(strict_types=1); class Calculator { public static function pow3(int $n) :
int { return $n ** 3; } } try { print Calculator::pow3("3"); } catch (TypeError $e) { print "TypeError!"; } // => "TypeError!" SF ☺
class Calculator { public static function pow3(int $n) : int
{ return $n ** 3; } } try { print Calculator::pow3(null); } catch (TypeError $e) { print "TypeError!"; } // ???
class Calculator { public static function pow3(int $n) : int
{ return $n ** 3; } } try { print Calculator::pow3(null); } catch (TypeError $e) { print "TypeError!"; } // => "TypeError!"
class Calculator { public static function pow3(?int $n) : int
{ return $n ** 3; } } try { print Calculator::pow3(null); } catch (TypeError $e) { print "TypeError!"; } // => 0 OVMMBCMF
w ܕએݴͰೖग़ྗΛ੍ݶ͢Δ w ؒҧ͍ͬͨํ͕Ͱ͖ͳ͍Α͏ʹ͢Δ w ޚతϓϩάϥϛϯάͷख๏ w ͍खʹաࣦ͕͋ͬͯඃ͕ٴͳ͍Α͏ʹ͢Δ w OPHBSCBHFBMMPXFEJO
w ͱ͍͏Α͏ͳ͜ͱ͕$PEF$PNQMFUFʹॻ͔ΕͯΔ w ձࣾͷຊ୨ʹ͋Γ·͢
IUUQTTQFBLFSEFDLDPNUXBEBQIQDPOGFSFODF ΑΓ࣮ફతͳ༰U@XBEB͞ΜͷεϥΠυΛಡΈ·͠ΐ͏
·ͱΊ w 1)1ʹܕએݴͱ͍͏ػೳ͕͋Δ w ܕએݴΛ͏͜ͱͰϝιουͷҾɾฦΓͷܕΛࢦఆͰ͖Δ w ೖྗΛ੍ݶ͢Δ͜ͱͰ͍ख͕ؒҧ͑Δ͜ͱΛࠔʹͰ͖Δ