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で始める型宣言
Search
Yoshihide Taniguchi
December 06, 2017
Programming
0
530
PHP7.2で始める型宣言
Talked in EC Tech Meeting in GMO Pepabo inc
Yoshihide Taniguchi
December 06, 2017
Tweet
Share
More Decks by Yoshihide Taniguchi
See All by Yoshihide Taniguchi
PHP がフロントエンドエンジニアになってみた // from PHPer to Frontend
gs3
1
310
ISUCONのすゝめ // OUR ISUCON
gs3
3
1.3k
オブジェクト指向設計とデザインパターンの基礎 / Basics of object oriented design and design pattern
gs3
2
100k
1人から始める大規模Webアプリケーションの言語バージョンアップ / version up PHP in large scale application
gs3
20
5k
PHP 5.4 ~ 5.6 での追加機能のおさらいとバージョンアップへの誘い / php54 to 56 and version up
gs3
1
2.3k
あの日見たバグを僕達はまだ公式ドキュメントで見れない / The bug we saw that day
gs3
1
1.5k
ペパボを支える大統一CI基盤と人々
gs3
2
4k
PHP 5.3.x のアプリを PHP 7.0.x で動かすためにした n 個のこと
gs3
1
1.5k
今までやってきたこと これからやりたいこと
gs3
0
2.3k
Other Decks in Programming
See All in Programming
fs2-io を試してたらバグを見つけて直した話
chencmd
0
220
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
530
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
MCP with Cloudflare Workers
yusukebe
2
220
命名をリントする
chiroruxx
1
380
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
130
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
740
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
良いユニットテストを書こう
mototakatsu
4
1.8k
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Designing Experiences People Love
moore
138
23k
Embracing the Ebb and Flow
colly
84
4.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Documentation Writing (for coders)
carmenintech
66
4.5k
Producing Creativity
orderedlist
PRO
341
39k
Making Projects Easy
brettharned
116
5.9k
The Language of Interfaces
destraynor
154
24k
Become a Pro
speakerdeck
PRO
26
5k
Being A Developer After 40
akosma
87
590k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
96
Mobile First: as difficult as doing things right
swwweet
222
9k
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 ೖྗΛ੍ݶ͢Δ͜ͱͰ͍ख͕ؒҧ͑Δ͜ͱΛࠔʹͰ͖Δ