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

20年ものの巨大レガシープロダクトを PHP 8.0にアップデートした際の対策と得られた知見

Akama Hitoshi
September 24, 2022

20年ものの巨大レガシープロダクトを PHP 8.0にアップデートした際の対策と得られた知見

Akama Hitoshi

September 24, 2022
Tweet

More Decks by Akama Hitoshi

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ w ੺ؒਔࢤ ͔͋·ͻͱ͠   ग़਎஍ɿౡࠜݝদߐࢢ  झຯ͸ϓϥϨʔϧͰܭࢉ͢Δ͜ͱ w

    αΠϘ΢ζגࣜձࣾʹ೥৽ଔೖࣾ  (BSPPO։ൃνʔϜʹॴଐ w 1)1ྺ͸ʙ೥͘Β͍  ϓϥϨʔϧCJUΧ΢ϯλ
  2. 

  3. 1)1Ξοϓσʔτͷεέδϡʔϧ  ೥ ೥      

            ϦϦʔε ࣄલௐࠪɾ৘ใऩू ຊௐࠪ Ͱͷ࣮૷ ςετ Ͱͷ࣮૷ ෆ۩߹मਖ਼ɾςετ ࣾ಺ద༻ ௐࠪ༻ϒϥϯνͰͷ࡞ۀ ໰୊ݕग़
  4. ϦϦʔεεύϯ w Ϋϥ΢υ൛(BSPPOͷϦϦʔεεύϯ͸௕͍  ϲ݄ʹճͷ৽ػೳ  ϲ݄͝ͱʹෆ۩߹मਖ਼ͳͲ w ෳ਺ͷόʔδϣϯ͕ฒߦͰ։ൃ͕ਐΉ w

    1)1ͷ։ൃதͰ΋ɺผͷϒϥϯνʹͲΜͲΜίϛοτ͞ΕΔ  ৽ػೳ։ൃͱฒߦͯ͠1)1ΞοϓσʔτΛߦ͏ඞཁ͕͋Δ
  5. ௐࠪίετ΁ͷରࡦ w ֤߲໨ͷௐࠪํ๏ͱௐࠪ݁ՌΛ෼͚Δ  มߋ఺ ௐࠪํ๏ ௐࠪ݁Ռ ϒϥϯν ϑΝΠϧ9ͰBCT Λ࢖༻

    ϒϥϯν ֘౰ͳ͠ TUSJDU@UZQFTͷϑΝΠϧͰ͜ΕΒͷؔ਺Λ࢖༻͢Δ͔ௐࠪ BCT ͳͲͷ਺ֶؔ਺͕TUSJDU@UZQFTʹਖ਼͘͠ै͏Α͏ʹͳͬͨ
  6. 

  7. ൺֱԋࢉࢠͷڍಈมԽ  w จࣈྻWT਺஋ͷൺֱํ๏͕มԽ  1)1 1)1 1)1 ਺஋ܗࣜ 'hoge'

    == 0 'hoge' == 0 '25.0' == 25 (int)'hoge' == 0 'hoge' == (string)0 (double)'25.0' == 25 0 == 0 'hoge' == '0' 25.0 == 25 true false true (ͱมΘΒͣ)
  8. ൺֱԋࢉࢠͷڍಈมԽ  w จࣈྻಉ࢜ͷൺֱ΋มΘΔ  1)1 1)1 '42' == '42

    ' '42' == '42 ' '42 ' ͕਺஋ܗࣜͰ͸ͳ͍ '42 ' ͕਺஋ܗࣜͱͳΔ จࣈྻͱͯ͠ൺֱ ਺஋ʹม׵ͯ͠ൺֱ false true
  9. มԽ͢Δԋࢉࢠɾؔ਺ w ݫີͰͳ͍ൺֱԋࢉࢠ͢΂ͯ ==, != ͷଞʹ΋ >, >=, <, <=,

    <=> ΋Өڹ w ഑ྻૢ࡞ܥͷඪ४ؔ਺ɿin_array(), array_search(), array_keys() w ιʔτܥͷؔ਺ɿsort(), rsort(), ...  ԋࢉࢠҎ֎ʹ΋มԽ͕͋Δʂ
  10. Կ͔ରࡦ͸ͳ͍͔ʁ w ίʔυ্ͰӨڹΛௐ΂Δͷ͸ݱ࣮తͰ͸ͳ͍  ຊ൪σʔλϕʔεͷ஋͸ଟछଟ༷ w ࣮ࡍʹςετ͢Δ͔͠ͳ͍  ࡉ͔͍ϩδοΫ͕มΘͬͨ͜ͱΛݕग़Ͱ͖Δ͔ʁ 

    if ($id == 0) { ... ࣮ߦ࣌ʹ݁Ռ͕Θ͔Δ͜ͱΛݕ஌Ͱ͖ͳ͍͔ʁ if ($id == 0) { ... if ($id == 0) { ... if ($id == 0) { ...
  11. NLUJNF HNNLUJNF w ೔෇͔Β6OJYλΠϜελϯϓΛٻΊΔ mktime($hour, $minute, $second, $month, $day, $year)

    w 1)1Ҏલ͸OVMM͸ʹΩϟετ͞Ε͍ͯͨ w 1)1Ҏ߱͸OVMM͕ݱࡏ࣌ࠁΛද͢Α͏ʹͳͬͨ  ݱࡏͷ೔࣌ʹΑͬͯ݁Ռ͕มΘΔόάͷՄೳੑ
  12. (BSPPOͰͷରॲํ਑ w ݸผରॲ͕Մೳͳ਺ͳΒͦͷ··ରॲΛਐΊΔ w ෆՄೳͳΒݹ͍ڍಈΛΤϛϡϨʔτ͢Δؔ਺Ͱஔ͖׵͑  ྫNC@TUSQPT  function cb_mb_strpos($haystack,

    $needle, $offset = 0, $encoding = null) { if ($needle === "" || $needle === null) { return false; } return mb_strpos($haystack, $needle, $offset, $encoding); }
  13. 1)1Τϥʔ w Τϥʔͷൃੜ࣍ୈɺΤϥʔϋϯυϥʹΑΓॲཧ͞ΕΔ w ྫ֎ͷΑ͏ʹݺग़ݩ΁ͱ఻೻͠ͳ͍ɻׂΓࠐΈϋϯυϥʹ͍ۙ w &@%&13&$"5&% &@/05*$& &@8"3/*/(ͳͲɺ͍͔ͭ͘ͷϨϕϧ͕͋Δ w

    FSSPS@SFQPSUJOHؔ਺ͰɺಛఆͷϨϕϧͷΤϥʔΛແࢹͤ͞Δ͜ͱ͕Ͱ͖Δ w 1)1ϓϩάϥϜશମͰ༗ޮͳΧελϜͷϋϯυϥΛهड़Մೳ w ΧελϜϋϯυϥͰ1)1ΤϥʔΛ཈੍͠ɺॲཧΛଓߦՄೳ 
  14. 1)1Τϥʔ w ͍͔ͭ͘ͷ&@/05*$&͕&@8"3/*/(ʹঢ֨ • Attempting to read an unde fi

    ned variable. • Attempting to read an unde fi ned property. • Attempting to read an unde fi ned array key. • Attempting to read a property of a non-object. • Attempting to access an array index of a non-array. • Attempting to convert an array to string. • Attempting to use a resource as an array key. • Attempting to use null, a boolean, or a fl oat as a string offset. • Attempting to read an out-of-bounds string offset. • Attempting to assign an empty string to a string offset. • جຊతʹ͸ @ ԋࢉࢠ͸ґવͱͯ͠༗ޮɻΤϥʔϋϯυϥͰͷରॲ΋໰୊ͳ͘Ͱ͖Δ 
  15. 1)1Τϥʔ w ͍··ͰجຊతʹΤϥʔϋϯυϥͰ཈੍͍ͯ͠ͳ͚Ε͹໰୊ͳ͍ • Attempting to write to a property

    of a non-object. • Attempting to append an element to an array for which the PHP_INT_MAX key is already used. • Attempting to use an invalid type (array or object) as an array key or string offset. • Attempting to write to an array index of a scalar value. • Attempting to unpack a non-array/Traversable. • Attempting to access unquali fi ed constants which are unde fi ned. w ͨͩɺ!ԋࢉࢠͰ཈੍͞Εͯͨ৔߹͸؏௨͢Δ w ରॲ1)1؀ڥͰ͜ΕΒͷ&@8"3/*/(Λัଊ͠ɺϞχλ͢Δ  /6--ʹର͢ΔϓϩύςΟͷॻ͖ࠐΈ͕݅ݟ͔ͭͬͨ