Upgrade to Pro — share decks privately, control downloads, hide ads and more …

型を意識したPHPアプリケーション開発

shin1x1
October 08, 2017

 型を意識したPHPアプリケーション開発

2017/10/08 PHPカンファレンス2017 https://github.com/shin1x1/phpcon2017

shin1x1

October 08, 2017
Tweet

More Decks by shin1x1

Other Decks in Technology

Transcript

  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 ม਺͸ܕΛ࣋ͨͳ͍ɺ஋͕ܕΛ࣋ͭ
  2. &MPRVFOU 3FQPTJUPSZ <?php declare(strict_types=1); function double(int $i): int { return

    $i * 2; } double(1); // 2 double(“5e”); // TypeError ܕએݴ
  3. &MPRVFOU 3FQPTJUPSZ // ܧঝ final class PriceWithTax extends Price {}

    ܧঝ $price = PriceWithTaxCalculator::calculate($price, $taxRate); // PriceWithTax ΋ Price ܕͳͷͰಈ͍ͯ͠·͏ $price = PriceWithTaxCalculator::calculate($price, $taxRate);
  4. &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); }