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

...意外に便利だった!!

chiroruxx
October 30, 2019

 ...意外に便利だった!!

2019/10/30 PHP勉強会@東京で話したスライドです。

chiroruxx

October 30, 2019
Tweet

More Decks by chiroruxx

Other Decks in Technology

Transcript

  1. ՄมݸҾ਺ؔ਺ function printArgs(...$inputs) { echo $inputs[0]; // apple echo $inputs[1];

    // banana echo $inputs[2]; // chocolate } printArgs('apple', 'banana', 'chocolate');
  2. Ҿ਺ͷΞϯύοΫ function printArgs($a, $b, $c) { // (ུ) } $args

    = ['apple', 'banana', 'chocolate']; printArgs(...$args);
  3. ྫ୊ w ࣗ෼Ͱఆٛͨ͠4UBUVTΫϥε͕͋Δ w 4UBUVTΛෳ਺ѻ͏Ϋϥε͕΄͍͠ w ഑ྻΛϥοϓͨ͠Ϋϥε w ཁ݅͸ҎԼ w

    ೚ҙͷ਺ͷ4UBUVTΠϯελϯεΛཁૉʹ࣋ͭ w 4UBUVTΠϯελϯεҎ֎Λཁૉʹ࣋ͬͯ͸͍͚ͳ͍ w Ωʔ͸࿈൪ͷΈʹ͢Δ ࿈૝഑ྻʹ͠ͳ͍
  4. ී௨ͷ࣮૷ class StatusCollection { private $items; public function __construct(array $items)

    { $this->items = $items; } } $items = [Status::random(), Status::random(), Status::random()]; new StatusCollection($items);
  5. ී௨ͷ࣮૷ class StatusCollection { private $items; public function __construct(array $items)

    { foreach ($items as $item) { if (!$item instanceof Status) { throw new InvalidArgumentException(); } } $this->items = $items; } } $items = [Status::random(), Status::random(), Status::random()]; new StatusCollection($items);
  6. ී௨ͷ࣮૷ class StatusCollection { private $items; public function __construct(array $items)

    { foreach ($items as $item) { if (!$item instanceof Status) { throw new InvalidArgumentException(); } } $this->items = array_values($items); } } $items = [Status::random(), Status::random(), Status::random()]; new StatusCollection($items);
  7. Λ࢖࣮ͬͨ૷ class StatusCollection { private $items; public function __construct(...$items) {

    foreach ($items as $item) { if (!$item instanceof Status) { throw new InvalidArgumentException(); } } $this->items = $items; } } $items = [Status::random(), Status::random(), Status::random()]; new StatusCollection(...$items);
  8. Λ࢖࣮ͬͨ૷ class StatusCollection { private $items; public function __construct(Status ...$items)

    { $this->items = $items; } } $items = [Status::random(), Status::random(), Status::random()]; new StatusCollection(...$items);