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

Upgrading Legacy to the Latest PHP Version

Upgrading Legacy to the Latest PHP Version

Your application runs on an old PHP version that is about to go out of support. How to upgrade without breaking the application? You will need the right tools for detecting and fixing those issues, as well as a way to verify that the application is still working correctly. In this presentation, I will share the strategy that I employed when upgrading millions of lines of untested code.

Anna Filina

October 28, 2021
Tweet

More Decks by Anna Filina

Other Decks in Programming

Transcript

  1. Anna Filina • Coding since 1997 (VB4) • PHP since

    2003 • Legacy archaeology • Test automation • Public speaking • Mentorship • YouTube videos
  2. phpco() { docker run --init -v $PWD:/mnt/src:cached --rm -u "$(id

    -u):$(id -g)" frbit/phpco:latest $@; return $?; }
  3. FILE: /mnt/src/app/controllers/MyController.php ------------------------------------------------------------------ FOUND 1 ERROR AFFECTING 1 LINE ------------------------------------------------------------------

    166 | ERROR | Using 'break' outside of a loop or switch structure | | is invalid and will throw a fatal error since PHP | | 7.0 ------------------------------------------------------------------
  4. final class Php56Compatibility { public static function each(array &$array) {

    if (current($array) === false) { return false; } $key = key($array); $value = current($array); next($array); return [ 1 => $value, 'value' => $value, 0 => $key, 'key' => $key, ]; } }
  5. • Can we decrypt what we just encrypted? • Can

    we decrypt what we already have in our database?
  6. • Connection object needs to be available. • Connection object

    now a mysqli type. • Field metadata represented differently. • Different methods for unbuffered queries.
  7. <?php class MyClass extends BaseClass { public function validate($field, $value)

    { //... } } class BaseClass { public function validate(string $field, $value, $message = null) { //... } }
  8. • Start testing. • Note the errors that appear. •

    Tune static analysis for those specific errors.
  9. • Is PHPUnit compatible with PHP? • Can it be

    updated? • Might need to upgrade PHPUnit.
  10. • Use PHPCompatibility • Use Psalm, PHPStan, etc. • Don't

    be afraid to fix the framework/libs. • Write tests.