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.8k
制約の力 - 状態を限定する -
shin1x1
4
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
430
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
Evolving DevOps Teams and Flexible Organizational Culture
kakehashi
1
260
AIで変わるテスト自動化:最新ツールの多様なアプローチ/ 20240910 Takahiro Kaneyama
shift_evolve
0
200
Jetpack Compose Modifier 徹底解説 / Jetpack Compose Modifier
wiroha
0
140
20240906_JAWS_Yamanashi_#1_leap_beyond_the_AWS_all_certifications
tsumita
1
280
20240912 JJUGナイトセミナー
mii1004
0
130
Creative UIs with Compose: DroidKaigi 2024
chrishorner
1
240
エンジニア向け会社紹介資料
caddi_eng
15
250k
ナレッジグラフとLLMの相互利用
koujikozaki
0
340
contenteditableと向き合う
kikuchikakeru
2
290
Developer Experienceを向上させる基盤づくりの取り組み事例集
coconala_engineer
0
120
Oracle Base Database Service:サービス概要のご紹介
oracle4engineer
PRO
0
13k
技術ブログや登壇資料を秒で作るコツ伝授します
minorun365
PRO
23
5.5k
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
73
8.9k
Why Our Code Smells
bkeepers
PRO
334
56k
GitHub's CSS Performance
jonrohan
1029
450k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
45
4.8k
For a Future-Friendly Web
brad_frost
174
9.3k
How STYLIGHT went responsive
nonsquared
93
5.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
278
13k
Bash Introduction
62gerente
608
210k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
89
16k
Optimising Largest Contentful Paint
csswizardry
30
2.8k
Creatively Recalculating Your Daily Design Routine
revolveconf
215
12k
Designing on Purpose - Digital PM Summit 2013
jponch
113
6.8k
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