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)です

Yoshihide Taniguchi

May 16, 2017
Tweet

More Decks by Yoshihide Taniguchi

Other Decks in Programming

Transcript

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  8. ؔ਺ͷฦΓ஋ͷఴࣈࢀর d

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

    View full-size slide

  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
    // )

    View full-size slide

  10. FNQUZ
    ʹ͕ࣜ౉ͤΔΑ͏ʹ d

    w͋ͷFNQUZ
    ʹม਺͚ͩͰͳ͕ࣜ͘౉ͤΔΑ͏ʹͳͬͨ
    if (empty(current_gmo_point())) {
    // . . .
    }

    View full-size slide

  11. DPOTUͰ഑ྻͷఆ਺Խ d

    wDPOTUΩʔϫʔυͰ഑ྻΛఆ਺ͱͯ͠એݴͰ͖ΔΑ͏ʹͳͬͨ
    const ARR = [1, 2, 3];
    print_r(ARR);
    // Array
    // (
    // [0] => 1
    // [1] => 2
    // [2] => 3
    // )

    View full-size slide

  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
    // )

    View full-size slide

  13. ྦྷ৐ԋࢉࢠ d

    w✽✽Ͱྦྷ৐ԋࢉ͕Ͱ͖ΔΑ͏ʹͳͬͨ
    w୹ॖ୅ೖԋࢉࢠͷ✽✽΋௥Ճ
    $num = 3 ** 2;
    $num **= 2;
    print $num;
    // => 81

    View full-size slide

  14. pOBMMZΩʔϫʔυ d

    wUSZDBUDIϒϩοΫʹpOBMMZΩʔϫʔυ͕௥Ճ͞Εͨ
    try {
    throw new Exception('௄໾5೥');
    } catch (Exception $e) {
    echo 'Caught exception: ', $e->getMessage(), "\n";
    } finally {
    echo '͸͍';
    }
    // => Caught exception: ௄໾5೥
    // ͸͍

    View full-size slide

  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!

    View full-size slide

  16. USBJU
    w୯Ұܧঝͳ1)1Ͱ

    ৼΔ෣͍Λڞ༗͢Δ࢓૊Έ
    wྫʣը૾ΛΞοϓϩʔυͰ͖Δ

    ৼΔ෣͍Λڞ༗͢Δ
    trait UploadImage
    {
    function upload($imagePath)
    {
    //...
    }
    }
    class ProductController
    {
    use UploadImage;
    // ...
    }
    class ShopController
    {
    use UploadImage;
    // ...
    }

    View full-size slide

  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!

    View full-size slide

  18. େ͖͍ϑΝΠϧͷΞοϓϩʔυ d

    w(#Ҏ্ͷϑΝΠϧ΋ΞοϓϩʔυͰ͖ΔΑ͏ʹͳͬͨ

    View full-size slide

  19. 1)1Ͱ࢖͑ͳ͘ͳΔػೳ ൈਮ

    wNZTRM@
    ؔ਺
    wFSFH
    ؔ਺
    wDBMM@VTFS@NFUIPE
    DBMM@VTFS@NFUIPE@BSSBZ

    wQIQJOJͷBTQ@UBHT
    wNFNDBDIFQFDMFYUFOTJPO
    wNFNDBDIF`E`FYUFOTJPO͸1)1YʹରԠ

    View full-size slide

  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

    View full-size slide

  21. w ࠓճ঺հ͠ͳ͔ͬͨ
    w ௥Ճͷؔ਺ɺΫϥεɺϝιου
    w ඇਪ঑ɾ࡟আͱͳͬͨػೳɾϞδϡʔϧ
    w ʹ͍ͭͯ͸1)1ϚχϡΞϧͷ෇࿥ʹ͋Γ·͢
    w IUUQQIQOFUNBOVBMKBBQQFOEJDFTQIQ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  25. ࢀߟɿ1)1ͷαϙʔτόʔδϣϯ
    IUUQQIQOFUTVQQPSUFEWFSTJPOTQIQΑΓ

    ηΩϡϦςΟαϙʔτ੾Εͨͷ͕೥લ ʂ

    ͸೥͍ͬͺ͍ηΩϡϦςΟαϙʔτ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide