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
型を意識したPHPアプリケーション開発
Search
shin1x1
October 08, 2017
Technology
5
10k
型を意識したPHPアプリケーション開発
2017/10/08 PHPカンファレンス2017
https://github.com/shin1x1/phpcon2017
shin1x1
October 08, 2017
Tweet
Share
More Decks by shin1x1
See All by shin1x1
PHPコードの実行モデルを理解する / Understanding-the-PHP-Execution-Model
shin1x1
0
1.7k
制約の力 - 状態を限定する -
shin1x1
3
3.9k
Apple Silicon Mac 時代の PHP 開発環境構築 2021 / php-dev-env-on-m1-mac-era
shin1x1
2
4.4k
Docker イメージのマルチアーキテクチャビルド / docker-muti-arch-build
shin1x1
1
420
Domain modeling with PHP / domain-modeling-with-php-en
shin1x1
0
190
ドメインをモデリングしてPHPコードに落とし込む / domain-modeling-with-php8
shin1x1
14
6.9k
PHP 8 で作る JSON パーサ / php8-json-parser
shin1x1
1
3.4k
Kubernetes で構築する PHP 開発環境 / php-development-environment-on-kubernetes
shin1x1
3
4.7k
独立したコアレイヤパターンの適用 - fortee 編 - / fortee-meets-independent-core-layer-pattern
shin1x1
0
3.4k
Other Decks in Technology
See All in Technology
AWSを始めた頃に陥りがちなポイントをまとめてみた
oshanqq
1
1.7k
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
1
160
プロデザ! BY リクルートvol.22_様々なプロダクト経験の中で活きたPdMのスキル
recruitengineers
PRO
3
170
Dify - LINE Bot連携 考え方と実用テクニック
uezo
5
1.1k
標準ライブラリの奥深アップデートを掘り下げよう!
logica0419
2
390
音声AIエージェントの世界とRetell AI入門 / Introduction to the World of Voice AI Agents and Retell AI
rkaga
3
470
夏休みの(最後の)宿題 for JuliaTokyo #12
antimon2
0
130
OCI コスト管理
ocise
1
110
X-Correlation Injections (or How to break server-side contexts)
fransrosen
0
360
Autonomous Database Cloud 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
15
39k
Javaにおける関数型プログラミンへの取り組み
skrb
5
110
Estrategias de escalabilidade para projetos web
jessilyneh
1
150
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
230
130k
Happy Clients
brianwarren
96
6.6k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Art, The Web, and Tiny UX
lynnandtonic
294
20k
The Invisible Customer
myddelton
119
13k
Mobile First: as difficult as doing things right
swwweet
220
8.8k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
27
7.4k
What's new in Ruby 2.0
geeforr
340
31k
Designing for Performance
lara
604
68k
How To Stay Up To Date on Web Technology
chriscoyier
785
250k
Principles of Awesome APIs and How to Build Them.
keavy
125
16k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Transcript
ܕΛҙࣝͨ͠ 1)1ΞϓϦέʔγϣϯ։ൃ ɹ!shin1x1 2017//08 phpcon 2017
https://php-genba.shin1x1.com/
D .BTBTIJ4IJOCBSB!TIJOY ΞδΣϯμ w1)1ͷܕγεςϜ wܕએݴΛར༻ͨ͠ίʔυ࣮ wυϝΠϯಛԽܕͷ࣮5JQT w͍͞͝ʹ
1)1ͷܕγεςϜ
&MPRVFOU 3FQPTJUPSZ $foo = 123; echo gettype($foo), PHP_EOL; => integer
$foo = 'Hello'; echo gettype($foo), PHP_EOL; => string $foo = [1, 2, 3]; echo gettype($foo), PHP_EOL; => array มܕΛ࣋ͨͳ͍ɺ͕ܕΛ࣋ͭ
&MPRVFOU 3FQPTJUPSZ echo 10 + 5, PHP_EOL; => 15 ԋࢉࢠJOUܕͱqPBUܕ͕ର
҉తܕม
&MPRVFOU 3FQPTJUPSZ echo 10 + "5", PHP_EOL; => 15 TUSJOH͕JOUʹม͞ΕΔ
҉తܕม
&MPRVFOU 3FQPTJUPSZ echo 10 + "5e", PHP_EOL; => 15 ҉తܕม
&MPRVFOU 3FQPTJUPSZ echo 10 + "5e2", PHP_EOL; => ??? ҉తܕม
&MPRVFOU 3FQPTJUPSZ echo 10 + "5e2", PHP_EOL; => 510 ҉తܕม
&MPRVFOU 3FQPTJUPSZ 5e2 ʢ5=Ծ෦, 2=ࢦ෦, 10=جʣ => 5 * (10
** 2) => 500 ˞ࢦදه
&MPRVFOU 3FQPTJUPSZ <?php declare(strict_types=1); function double(int $i): int { return
$i * 2; } double(1); // 2 double(“5e”); // TypeError ܕએݴ
D .BTBTIJ4IJOCBSB!TIJOY 1)1ͷܕγεςϜ w͕ܕΛ࣋ͭ w҉తܕมͰॊೈʹ։ൃ wܕએݴͰݫີʹ։ൃ wϢʔβ͕ελΠϧΛબͰ͖Δ
ܕΛ׆༻ͨ͠1)1ίʔυͷ࣮
D .BTBTIJ4IJOCBSB!TIJOY FY੫ࠐΈՁ֨ͷࢉग़ wՁ֨ ফඅ੫ খҎԼΓࣺͯ wՁ֨ਖ਼ͷ
wফඅ੫খͱ͢Δʢʣ
D .BTBTIJ4IJOCBSB!TIJOY %FNP wܕએݴແ͠ wεΧϥʔܕͰܕએݴ wϢʔβఆٛܕͰܕએݴ
D .BTBTIJ4IJOCBSB!TIJOY %FNP https://github.com/shin1x1/phpcon2017
D .BTBTIJ4IJOCBSB!TIJOY υϝΠϯʹಛԽͨ͠ܕΛ࡞Δ wΞϓϦέʔγϣϯυϝΠϯΛදݱ wυϝΠϯϧʔϧΛݕূ wܕએݴʹΑΔදݱͱڧ੍
&MPRVFOU 3FQPTJUPSZ // ܕએݴແ͠ function calculate($price, $taxRate) // υϝΠϯಛԽܕͰܕએݴ function
calculate( Price $price, TaxRate $taxRate): PriceWithTax
υϝΠϯಛԽܕͷ࣮5JQT
D .BTBTIJ4IJOCBSB!TIJOY ҆қʹܧঝΛΘͳ͍ wܧঝݩΫϥεܕͷద߹Λ͙ wܧঝݩϝιουؚ͕·Εͯ͠·͏ wҕৡτϨΠτͰڞ༗
&MPRVFOU 3FQPTJUPSZ // ܧঝ final class PriceWithTax extends Price {}
ܧঝ $price = PriceWithTaxCalculator::calculate($price, $taxRate); // PriceWithTax Price ܕͳͷͰಈ͍ͯ͠·͏ $price = PriceWithTaxCalculator::calculate($price, $taxRate);
D .BTBTIJ4IJOCBSB!TIJOY Πϛϡʔλϒϧʹ͢Δͱ҆શ wશίϯετϥΫλ wෆม݅ݕূ͕ҰͰࡁΉ wϛϡʔλϒϧͳΒݕূ
D .BTBTIJ4IJOCBSB!TIJOY ϑΝΫτϦϝιου wίϯετϥΫλΛQSJWBUF wϑΝΫτϦϝιου wҾʹΑΔόϦΤʔγϣϯ
&MPRVFOU 3FQPTJUPSZ ϑΝΫτϦϝιου public static function of(float $value): self {
return new self($value); } public static function ofByInt(int $value): self { return new self($value / 100); }
&MPRVFOU 3FQPTJUPSZ ϑΝΫτϦϝιου // float TaxRate::of(0.08); // int TaxRate::ofByInt(8);
D .BTBTIJ4IJOCBSB!TIJOY ։ൃͰͷܕݕࠪ wࣗಈςετ $* w1IQ4UPSN w1IBO
D .BTBTIJ4IJOCBSB!TIJOY 1IQ4UPSN wΤσΟλ ϦΞϧλΠϜͳνΣοΫ w*OTQFDU$PEFT ϓϩδΣΫτશମΛҰׅνΣοΫ w6TBHFTPG ܕͷར༻ҰཡΛྻڍ
D .BTBTIJ4IJOCBSB!TIJOY 1IBO w1)1Ͱ࣮͞Εͨ$-*πʔϧ wܕෆҰகTUSJDUҧͳͲΛݕ w$*Ͱܕݕࠪ https://github.com/phan/phan
͍͞͝ʹ
wܕએݴͰܕΛڧ੍ wυϝΠϯΛܕͰදݱ wܕͰؾ͍͍࣋ͪ։ൃΛ D .BTBTIJ4IJOCBSB!TIJOY ܕΛ׆༻ͨ͠։ൃ
D .BTBTIJ4IJOCBSB!TIJOY !TIJOY !TIJOY D .BTBTIJ4IJOCBSB!TIJOY