CarbonとMutableオブジェクトの話

 CarbonとMutableオブジェクトの話

CarbonでMutableとかImmutableの概念を覚えようねの話。

F04982ad61107b5408ad139966596316?s=128

Ryo Tomidokoro

December 26, 2018
Tweet

Transcript

  1. CarbonͱMutableΦϒδΣΫτͷ࿩ 1)1ษڧձ

  2. ໊લ෋ॴ྄ 3ZP5PNJEPLPSP ৬ۀ8FC"QQMJDBUJPO&OHJOFFS ॴଐ*OOPWBUPS+BQBO*OD ࡶ༻୲౰ झຯόεέοτϘʔϧ؍ઓ

  3. Carbonͱ͸ʁ

  4. $BSCPOͱ͸ʁ Carbon - A simple PHP API extension for DateTime.

    DateTimeΫϥεͷAPI֦ு IUUQTDBSCPOOFTCPUDPN
  5. $BSCPOͱ͸ʁ ศར ௚ײతͰ෼͔Γ΍͍͢ ๛෋ͳAPIͱυΩϡϝϯτ

  6. MutableΦϒδΣΫτͱ͸ʁ

  7. .VUBCMFΦϒδΣΫτͱ͸ʁ MutableΦϒδΣΫτ ͦͷঢ়ଶΛม͑Δ͜ͱ͕ग़དྷΔΦϒδΣΫτ ImmutableΦϒδΣΫτ ͦͷঢ়ଶΛม͑Δ͜ͱ͕ग़དྷͳ͍ΦϒδΣΫτ ࢀর) Πϛϡʔλϒϧ - Wikipedia |

    https://ja.wikipedia.org/wiki/Πϛϡʔλϒϧ
  8. ຊ೔ͷେࣄͳςʔϚ

  9. ຊ೔ͷॏཁࣄ߲ 1. CarbonΛ௨ͯ͡MutableɺImmutableΛ֮͑Α͏ ಛʹImmutableͷ֓೦͸ͱͯ΋େ੾ 2. CarbonͷίʔυϨϏϡʔྗUP Carbon͸࣌ʹةݥͳίʔυΛੜΈग़͢ ৯͍ࢭΊ·͠ΐ͏ʂ

  10. ຊ೔ͷॏཁࣄ߲ ͔͠͠ɺී௨ʹίʔυྫΛಡΜͰ΋๞͖ΔͷͰ… ΫΠζܗࣜͰίʔυϨϏϡʔͯ͠Έ·͠ΐ͏ʂ

  11. CarbonΫΠζ

  12. $BSCPOΫΠζ A܅͸usersςʔϒϧʹొ࿥͞ΕͨϢʔβσʔλͷத ͔Βɺ࠷ۙ̏ϲ݄Ҏ಺ʹొ࿥͞ΕͨϢʔβσʔλΛ நग़͢ΔॲཧΛ࡞Δ͜ͱʹͳΓ·ͨ͠ɻ ͔͠͠ɺA܅͕࡞੒ͨ͠ϓϩάϥϜʹ͸໰୊͕͋ͬ ͯਖ਼͘͠ϢʔβσʔλΛநग़Ͱ͖·ͤΜͰͨ͠ɻ

  13. $BSCPOΫΠζ ࣍ͷίʔυͷԿߦ໨ʹ໰୊͕͋ΔͰ͠ΐ͏͔ʁ ͦͯ͠ɺͦΕ͸ԿނͰ͠ΐ͏͔ʁ

  14. $BSCPOΫΠζ ࣮ࡍͷϓϩάϥϜʢൈਮʣ 1. Կߦ໨͕໰୊ʁ 2. Կ͕໰୊ʁ

  15. CarbonΫΠζ - ղ౴ฤ

  16. $BSCPOΫΠζ 1. Կߦ໨͕໰୊ʁ -> 14ߦ໨ 2. Կ͕໰୊ʁ -> subMonthϝιουͰ$todayࣗମ΋มߋ͞Εͯ͠·͏

  17. CarbonΫΠζ - ໛ൣղ౴1

  18. $BSCPOΫΠζ copy()ϝιουΛ࢖͏ $todayͷෳ੡Λ࡞Δ͜ͱͰɺ$todayࣗମͷมߋΛආ͚Δ

  19. CarbonΫΠζ - ໛ൣղ౴2

  20. $BSCPOΫΠζ Carbon2 CarbonImmutableͳΒɺ$today͸ImmutableͳͷͰෆม

  21. $BSCPOΫΠζ Carbon2 AliasΛ࢖͑͹ɺϓϩάϥϜͷมߋແ͠ɻ

  22. ·ͱΊ

  23. ·ͱΊ ɾCarbon͸ѱ͘ͳ͍ ɾAPI֦ுͷੑ࣭Λ͖ͪΜͱ೺Ѳ͢Δ͜ͱ ɾMutable, ImmutableΦϒδΣΫτΛ֮͑Α͏

  24. ͓·͚

  25. $BSCPOͱ$BSCPO MutableΦϒδΣΫτ ImmutableΦϒδΣΫτ ɾCarbon1ܥ ɾDateTimeΫϥεͷ֦ுAPI ɾCarbon2ܥ ɾDateTimeImmutableΫϥεͷ֦ுAPI

  26. %BUF5JNF*NNVUBCMFΫϥε ࢀর) PHPϚχϡΞϧ | http://php.net/manual/ja/class.datetimeimmutable.php