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

PHP 5.4 ~ 5.6 での追加機能のおさらいとバージョンアップへの誘い / php54 to 56 and version up

PHP 5.4 ~ 5.6 での追加機能のおさらいとバージョンアップへの誘い / php54 to 56 and version up

社内のテックミーティングの資料(公開 ver)です

B70c88a9a107334fa64a69e010af3cc6?s=128

Yoshihide Taniguchi

May 16, 2017
Tweet

Transcript

  1. d1)1όʔδϣϯ্͕Δͱศར͡ΌΜd &$ج൫୩ޱHVTTBO &$5FDI.5( 1)1dͰͷ ௥Ճػೳͷ͓͞Β͍ͱ όʔδϣϯΞοϓ΁ͷ༠͍

  2. എܠ wϩʔϧ"ͷ1)1͕Y͔ΒʹͳΓ·ͨ͠ w1)1dͰ௥Ճ͞ΕͨػೳΛ஌͍ͬͯ·͔͢ʁ w๻͸͋Μ·Γ஌Γ·ͤΜͰͨ͠ wطଘͷίʔυ͔Β৽ػೳ͸ֶ΂·ͤΜ wࣗൃతͳֶश͕ඞཁͰ͢ ˞ ॾ໰୊͔Βɺࠓ͙͢࢖͏ͱ໰୊͕͋Γ·͢

  3. 1)1Ͱͳ͘ΛબΜͩཧ༝ʹ͍ͭͯ͸ˣΛࢀর wIUUQTTQFBLFSEFDLDPNHTBGBMTFSJKJBOUBCBHVXPQVEB IBNBEBHPOHTIJEPLJZVNFOUPEFKJBOSFOBJ

  4. ࠓճ͓࿩͍ͨ͜͠ͱ w1)1͔Β·Ͱʹ௥Ճ͞Εͨػೳʹ͍ͭͯ wಠஅͱภݟͰൈਮ͠·ͨ͠ w1)1dͰඇਪ঑ʹͳΔɾແ͘ͳΔػೳʹ͍ͭͯ w͜Ε͔Β࢖Θͳ͍ɺফͤͦ͏ͳΒফ͢ wόʔδϣϯΞοϓͯ͠Έ·ͤΜ͔ʁͱ͍͏͓༠͍

  5. ✂͔͜͜Βػೳ঺հ✂

  6. <>ʢdʣ wBSSBZ  Λ<>Ͱॻ͚ΔΑ͏ʹͳͬͨ $men = [‘Jon’, ‘Bon’, ‘Jovi’]; //

    $men = array(‘Jon’, ‘Bon’, ‘Jovi’); ͱ౳Ձ
  7. "SSBZ 4USJOHͷσϦϑΝϨϯεʢdʣ w഑ྻɺจࣈྻΛ௚઀ఴࣈͰࢀরͰ͖ΔΑ͏ʹͳͬͨ print [1, 2, 3, 4][0]; // =>

    1 print ‘colorme’[4]; // => ‘r’
  8. ؔ਺ͷฦΓ஋ͷఴࣈࢀর d wؔ਺ʢϝιουʣͷฦΓ஋Λఴ͑ࣈͰ௚઀ࢀরͰ͖ΔΑ͏ʹͳͬͨ function simple_array() { return [1, 2, 3];

    } print simple_array()[1]; // => 2
  9. BSSBZ@DPMVNO  wd wଟ࣍ݩ഑ྻʹ͋Δ
 ಛఆͷΩʔͷ஋Λऔಘ͢Δؔ਺ $array = [ [ 'id'

    => 101, 'name' => 'Jim', 'position' => 'guitar', ], [ 'id' => 102, 'name' => 'Corey', 'position' => 'vocals', ] ]; print_r(array_column($array, 'name')); // Array // ( // [0] => Jim // [1] => Corey // )
  10. FNQUZ  ʹ͕ࣜ౉ͤΔΑ͏ʹ d w͋ͷFNQUZ  ʹม਺͚ͩͰͳ͕ࣜ͘౉ͤΔΑ͏ʹͳͬͨ if (empty(current_gmo_point())) {

    // . . . }
  11. DPOTUͰ഑ྻͷఆ਺Խ d wDPOTUΩʔϫʔυͰ഑ྻΛఆ਺ͱͯ͠એݴͰ͖ΔΑ͏ʹͳͬͨ const ARR = [1, 2, 3]; print_r(ARR);

    // Array // ( // [0] => 1 // [1] => 2 // [2] => 3 // )
  12. ԋࢉࢠ d wՄม௕Ҿ਺ΛԋࢉࢠͰ
 දݱͰ͖ΔΑ͏ʹͳͬͨ w͞Β͹GVOD@HFU@BSHT   function puts_nums(...$nums) {

    print_r($nums); } puts_nums(1); puts_nums(1, 2); puts_nums(1, 2, 3); // Array // ( // [0] => 1 // ) // Array // ( // [0] => 1 // [1] => 2 // ) // Array // ( // [0] => 1 // [1] => 2 // [2] => 3 // )
  13. ྦྷ৐ԋࢉࢠ d w✽✽Ͱྦྷ৐ԋࢉ͕Ͱ͖ΔΑ͏ʹͳͬͨ w୹ॖ୅ೖԋࢉࢠͷ✽✽΋௥Ճ $num = 3 ** 2; $num

    **= 2; print $num; // => 81
  14. pOBMMZΩʔϫʔυ d wUSZDBUDIϒϩοΫʹpOBMMZΩʔϫʔυ͕௥Ճ͞Εͨ try { throw new Exception('௄໾5೥'); } catch

    (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } finally { echo '͸͍'; } // => Caught exception: ௄໾5೥ // ͸͍
  15. ։ൃ༻$-*8FCαʔό d w8FCαʔό͕$-*Ϟʔυͷ1)1ʹ૊Έࠐ·Εͨ wϧʔτ63-ʹΞΫηε͢ΔͱJOEFY QIQcIUNM Λฦͯ͘͠ΕΔ $ echo ‘Hello, PHP!’

    > index.html $ php -S localhost:7000 -t . $ curl localhost:7000 Hello, PHP!
  16. USBJU w୯Ұܧঝͳ1)1Ͱ
 ৼΔ෣͍Λڞ༗͢Δ࢓૊Έ wྫʣը૾ΛΞοϓϩʔυͰ͖Δ
 ৼΔ෣͍Λڞ༗͢Δ trait UploadImage { function upload($imagePath)

    { //... } } class ProductController { use UploadImage; // ... } class ShopController { use UploadImage; // ... }
  17. ։ൃ༻$-*8FCαʔό d w8FCαʔό͕$-*Ϟʔυͷ1)1ʹ૊Έࠐ·Εͨ wϧʔτ63-ʹΞΫηε͢ΔͱJOEFY QIQcIUNM Λฦͯ͘͠ΕΔ $ echo ‘Hello, PHP!’

    > index.html $ php -S localhost:7000 -t . $ curl localhost:7000 Hello, PHP!
  18. େ͖͍ϑΝΠϧͷΞοϓϩʔυ d w(#Ҏ্ͷϑΝΠϧ΋ΞοϓϩʔυͰ͖ΔΑ͏ʹͳͬͨ

  19. 1)1Ͱ࢖͑ͳ͘ͳΔػೳ ൈਮ wNZTRM@ ؔ਺ wFSFH ؔ਺ wDBMM@VTFS@NFUIPE DBMM@VTFS@NFUIPE@BSSBZ  wQIQJOJͷBTQ@UBHT

    wNFNDBDIFQFDMFYUFOTJPO wNFNDBDIF`E`FYUFOTJPO͸1)1YʹରԠ
  20. 1)1dͰEFQSFDBUFͳػೳ ൈਮ w  w $MBTT/BNF ͳίϯετϥΫλ w ඇTUBUJDϝιουͷTUBUJDͳݺͼग़͠ w

     w FYUNDSZQUϞδϡʔϧ w  3'$ͷஈ֊  w @@BVUPMPBE   w DSFBUF@GVODUJPO   w FBDI   w ୈҾ਺ͷͳ͍QBSTF@TUS 
  21. w ࠓճ঺հ͠ͳ͔ͬͨ w ௥Ճͷؔ਺ɺΫϥεɺϝιου w ඇਪ঑ɾ࡟আͱͳͬͨػೳɾϞδϡʔϧ w ʹ͍ͭͯ͸1)1ϚχϡΞϧͷ෇࿥ʹ͋Γ·͢ w IUUQQIQOFUNBOVBMKBBQQFOEJDFTQIQ

  22. ✂͜͜·Ͱػೳ঺հ✂

  23. όʔδϣϯΞοϓͯ͠Έ·ͤΜ͔ʁ w΍Δͱීஈͷ։ൃͰಘΒΕͳ͍஌ݟ͕ಘΒΕ·͢ wࠓͳΒϩʔϧ"Ͱ΍ͬͨͱ͖ͷϩάΛࢀߟॻʹͰ͖·͢ʂ w͔͠΋ϩʔϧ"ΑΓίʔυྔଟ͍ϩʔϧ͸ແ͍ʂ wόʔδϣϯΞοϓͷλεΫ͕߱ͬͯ͘Δ͜ͱ͸ແ͍ w΍Δؾ͋Δਓ͕֮ޛܾΊͯ࣌ؒऔΓʹߦ͔͘͠ͳ͍ w΍ΔͳΒશྗͰαϙʔτ͠·͢ʂʂʂʂ̍̍

  24. ͢΂ͯͷґଘؔ܎ʹ͍ͭͯ࠷৽ͷόʔδϣϯʹ௥ै͢Δʹ͸ෆஅ ͷ౒ྗ͕ඞཁ͕ͩɺී௨͸ɺͦΕΛߦ͏͚ͩͷϝϦοτ͕͋Δɻ ΞοϓάϨʔυʹΑͬͯɺ͠͹͠͹ੑೳͷ޲্΍όάϑΟοΫε ͕ಘΒΕΔ͠ɺͱ͖ʹ͸க໋తͳηΩϡϦςΟͷύον͕౰ͯΒ ΕΔɻͦΕ͚ͩΛ໨౰ͯʹґଘؔ܎ͷΞοϓάϨʔυΛߦ͏΂͖ Ͱ͸ͳ͍͕ɺҰൠʹɺΞοϓάϨʔυ͸ྑ͍͜ͱͰ͋Δɻ ΫϦεɾόʔνϟϧʮϨΨγʔιϑτ΢ΣΞվળΨΠυʯᠳӭࣾ

  25. ࢀߟɿ1)1ͷαϙʔτόʔδϣϯ IUUQQIQOFUTVQQPSUFEWFSTJPOTQIQΑΓ ηΩϡϦςΟαϙʔτ੾Εͨͷ͕೥લ ʂ  ͸೥͍ͬͺ͍ηΩϡϦςΟαϙʔτ

  26. όʔδϣϯΞοϓͷԸܙ wύϑΥʔϚϯεͷ޲্Ҏ֎ʹ΋ɺجຊతʹ͍͍͜ͱͣ͘Ί wηΩϡϦςΟϦεΫ͕Լ͕Δ w։ൃͷॊೈੑɾݎ࿚ੑ্͕͕Δɾ্͛΍͘͢ͳΔ wʢ࠷৽ͷʣػೳ͕૿͑Δ wͦΕΛલఏͱͨ͠ศརͳϥΠϒϥϦ͕࢖͑Δ wʹ໰୊ղܾͷબ୒ࢶ͕૿͑Δ wࣾ֎ͷ৘ใʹΞλον͠΍͘͢ͳΔɾ੒ՌΛࣾ֎ʹൃද͠΍͘͢ͳΔ wͳͲͳͲ

  27. ·ͱΊ w1)1dͰ௥Ճ͞ΕͨػೳΛ঺հ͠·ͨ͠ w1)1dͰඇਪ঑ɾ࡟আͱͳͬͨػೳΛ঺հ͠·ͨ͠ w1)1ͷόʔδϣϯΞοϓʹ༠͍·ͨ͠

  28. ࢀߟ wQIQϚχϡΞϧɿ෇࿥ wIUUQQIQOFUNBOVBMKBBQQFOEJDFTQIQ wQIQSGD wIUUQTXJLJQIQOFUSGD