PHP のドキュメントを読んで PHP のことをもっと知ろう

PHP のドキュメントを読んで PHP のことをもっと知ろう

at PHP BLT #3

Ff822949384025796e11fd7f681df060?s=128

Katsuhiro OGAWA

March 01, 2016
Tweet

Transcript

  1. 1)1ͷυΩϡϝϯτΛಡΜͰ 1)1ͷ͜ͱΛ΋ͬͱ஌Ζ͏ খ઒༤େ!pWFTUS 1 PHP BLT #3

  2. খ઒༤େ (͓͕Θ͔ͭͻΖ) @fivestr Racing Driver (Amateur) Author of "Perfect PHP"

    CTO at Ancar Inc. 2
  3. Έͳ͞Μ1)1ͷ࠷৽ಈ޲͸νΣοΫͯ͠·͔͢ʁ w 1)1ͰԿ͕৽͘͠ͳ͔ͬͨ w ࠓޙͲͷΑ͏ͳػೳ͕௥Ճ͞ΕΔ͔ 3

  4. 1)1 w εΧϥʔλΠϓώϯτ w ϦλʔϯλΠϓώϯτ w ԋࢉࢠ /VMM߹ମԋࢉࢠ  w

    ԋࢉࢠ εϖʔεγοϓԋࢉࢠ  w ແ໊Ϋϥε 4
  5. 1)1&SSPS w 5ISPXBCMF w &SSPS w &YDFQUJPO w ͪͳΈʹ#BTF&YDFQUJPOͰ͸ͳ͘ͳΓ·ͨ͠ 5

  6. use Entity\{Article, Author, Comment}; 6

  7. ҠߦυΩϡϝϯτΛಡΈ·͠ΐ͏ w <1)1Y͔Β1)1Y΁ͷҠߦ>
 IUUQQIQOFUNBOVBMKBNJHSBUJPOQIQ  w ֤ϝδϟʔϚΠφʔόʔδϣϯ͝ͱʹ
 ҠߦυΩϡϝϯτ͕͋Γ·͢ w 

       w υΩϡϝϯτͷτοϓ͔ΒḷΕ·͢ 7
  8. ҠߦυΩϡϝϯτ͍͢͝ w جຊతʹ͢΂ͯͷมߋ͕·ͱΊΒΕ͍ͯ·͢ w ͔͠΋͍͍ͩͨ຋༁͞Ε͍ͯ·͢ w NUBLBHJ͞Μຊ౰ʹ͋Γ͕ͱ͏ 8

  9. ࠓޙͷಈ͖͸Ͳ͏΍ͬͯݟ͍͚ͯ͹͍͍ͷʁ w ҠߦυΩϡϝϯτΛಡΊ͹ϦϦʔε͞Εͨ
 ৘ใ͸Θ͔ΔΑ͏ʹͳΓ·ͨ͠ w ͜Ε͔Β௥Ճ͞ΕΔػೳͱ͔͸
 Ͳ͏΍ͬͯ஌Ε͹Α͍ͷͰ͠ΐ͏͔ 9

  10. 1)13'$ w 3'$ͷϖʔδΛݟΔͱࠓޙͷಈ͖Λ
 νΣοΫͰ͖·͢ w IUUQTXJLJQIQOFUSGD 10

  11. 3'$ͷಈ͖ w %SBGU%JTDVTTJPO7PUJOH w "DDFQUFE*NQMFNFOUBUJPO w %FDMJOF w ౤ථͷ݁Ռͷࢍ੒͕ͳ͍ͱ٫Լ͞ΕΔ 11

  12. *NQMFNFOUFE 12

  13. <>7PJE3FUVSO5ZQF w WPJE ໭Γ஋͕ͳ͍ ΛϦλʔϯ
 λΠϓώϯτ͕ఆٛͰ͖ΔΑ͏ʹ 13

  14. function process($data) :void { ...
 } 14

  15. <>4VQQPSU$MBTT$POTUBOU7JTJCJMJUZ w Ϋϥεఆ਺ʹΞΫηεम০ࢠΛ
 ઃఆͰ͖ΔΑ͏ʹ͢Δ 15

  16. class Foo { private const BAR = 'baz'; } 16

  17. "DDFQUFE 1FOEJOH*NQMFNFOUFE 17

  18. "MMPXTQFDJGZJOHLFZTJOMJTU w MJTU Ͱ࿈૝഑ྻͷΩʔΛࢦఆͯ͠
 ల։Ͱ͖ΔΑ͏ʹ͢Δ 18

  19. list( 'type' => $type, 'value' => $value, ) = $attrs;

    19
  20. 7PUJOH 20

  21. (FOFSBMJ[FTVQQPSUPGOFHBUJWFTUSJOHP⒎TFUT w จࣈྻͷΦϑηοτࢦఆʹϚΠφεͷ஋Λ
 ࢦఆͰ͖ΔΑ͏ʹ͢Δ w TVCTUSͳͲؔ਺Ͱ͸αϙʔτ͞Ε͍ͯͨ w ͍·ͷͱ͜Ζ൓ର͸Ͱ͍ͯͳ͍ͷͰ௨Γͦ͏ 21

  22. $str = 'abcdef'; var_dump($str[-2]); // => string(1) "e" 22

  23. 6OEFS%JTDVTTJPO 23

  24. 5SBJUTXJUIJOUFSGBDFT w τϨΠτʹΠϯλʔϑΣΠεΛ
 ࣮૷Ͱ͖ΔΑ͏ʹ͢Δ w ͢͹Β͍͠ w ͥͻ࣮૷͍͖͍ͯͨͩͨ͠ 24

  25. trait LoggerInjectTrait implements LoggerAwareInterface { protected $logger; /** @Inject */

    public function setLogger(LoggerInterface $logger) { $this->logger = $logger; } } 25
  26. %FDMJOF 26

  27. 1SPQFSUZ"DDFTTPST4ZOUBY w ΫϥεͷϓϩύςΟͷΞΫηαఆٛ w ΊͬͪΌཉ͔ͬͨ͠ͷʹͳΜͰ 27

  28. $MBTT.FUBEBUB "OOPUBUJPOT w ΞϊςʔγϣϯͷωΠςΟϒαϙʔτ͸
 ٫Լ͞Ε͍ͯΔ w %PDίϝϯτͷΞϊςʔγϣϯΛѻ͏ ʮ"OOPUBUJPOTJOEPDCMPDLʯ΋
 *OBDUJWFʹͳ͍ͬͯΔ 28

  29. ·ͱΊΔͱ 29

  30. 1)1υΩϡϝϯτΛಡ΋͏ w ҠߦΨΠυΛಡΉͱϦϦʔεͷ಺༰͕
 ೺ѲͰ͖·͢ w 3'$ΛಡΉͱࠓޙͷػೳ௥ՃͳͲͷಈ޲Λ
 ݟΔ͜ͱ͕Ͱ͖·͢ 30

  31. ͍͞͝ʹ 31

  32. 1)1ΤϯδχΞͱ J04ΤϯδχΞͱ "OESPJEΤϯδχΞͱ σβΠφʔͱ ͱ΋͔͘Ұॹʹಇ͍ͯ͘ΕΔํΛืू͍ͯ͠·͢ʂʂ 32