Bringing Old Legacy Apps To PHP 7 and Beyond - Midwest PHP 2017

Bringing Old Legacy Apps To PHP 7 and Beyond - Midwest PHP 2017

Most developers don't get the luxury of working on a greenfield project using a web framework of their choice. Often times we find ourselves inheriting a legacy codebase written years ago for an end-of-life version of PHP and a now-defunct web framework. The initial temptation might be, "I'll just rewrite all this on x framework". But hold on there my framework friend, a rewrite is costly and is rarely the correct answer.

We'll discuss some common pitfalls when getting a legacy codebase ready for PHP 7 and what we can do to make the upgrade path as painless as possible. These incremental changes will keep the business running while improving security, stability and maintainability of the codebase.

8c090cc1ccd623a146ddd9159b1bf7e2?s=128

Sammy Kaye Powers

March 17, 2017
Tweet

Transcript

  1. 3.
  2. 15.

    “Legacy” /leɡəsē/ • Requires an EOL version of PHP •

    No automated tests • Has outdated dependencies • No autoloading • No sign of “single responsibility”
  3. 16.
  4. 17.

    “Legacy” We’ll assume …means any code that can be improved

    (at least for this talk) @SammyK #mwphp17 joind.in/talk/82979
  5. 22.

    Around Poke • Composer &/or autoloading? • Documentation? (Look for

    hidden docs!) • Framework/Dependencies? (How out-dated?) • How is database layer implemented? • How is config handled? • How are front-end assets handled? • Are there tests? • Production env (PHP version)
  6. 24.
  7. 25.
  8. 26.
  9. 28.

    Consider the Stakeholders I’ll need 80 hours to refactor the

    user auth & ACL @SammyK #mwphp17 joind.in/talk/82979
  10. 29.

    Consider the Stakeholders • Most critical security holes • Most

    critical bugs • Most critical features • Use data from static analysis Make a plan
  11. 33.

    Kickass Development Environments with Docker David McKay Tomorrow @ 11

    AM in Ballroom D @SammyK #mwphp17 joind.in/talk/82979
  12. 35.
  13. 38.
  14. 42.

    7.1

  15. 50.

    PHP 7 Quick tricks to refactor to (in order of

    ease) @SammyK #mwphp17 joind.in/talk/82979
  16. 56.
  17. 57.
  18. 61.
  19. 65.

    PHP 7.0 “Gotchas” Another bird with the PHP 7.0 stone

    ext/mssql functions instead use sqlsrv_*(), odbc_*(), PDO
  20. 66.
  21. 68.
  22. 69.

    PHP 7.0 “Gotchas” Uniform Variable Syntax Change in evaluating indirect

    expressions @SammyK #mwphp17 joind.in/talk/82979
  23. 70.
  24. 72.
  25. 74.

    7.x

  26. 75.
  27. 76.

    5.x

  28. 77.

    5.x

  29. 79.

    7.x

  30. 80.

    7.x

  31. 81.

    7.x

  32. 82.

    7.x Notice: Array to string conversion in / foo.php on

    line 6 Notice: Undefined variable: Array in / foo.php on line 6
  33. 83.
  34. 84.
  35. 85.
  36. 86.
  37. 97.
  38. 100.
  39. 104.
  40. 115.

    PHP 7.0 Features Scalar Type Declarations function foo(string $name,
 int

    $age,
 bool $isGreat,
 float $income)
 { /* */ }
  41. 116.

    PHP 7.0 Features Scalar Type Declarations function foo(string $name,
 int

    $age,
 bool $isGreat,
 float $income)
 { /* */ }
  42. 119.
  43. 122.

    PHP 7.0 Features $bar = isset($_GET[‘foo’]) ? $_GET[‘foo’] : null;

    Null coalesce operator $bar = $_GET[‘foo’] ?? null;
  44. 127.
  45. 132.
  46. 139.

    Class constant visibility class Foo {
 public const FOO =

    0; protected const BAR = 1; private const BAZ = 2; } PHP 7.1 Features
  47. 141.

    `iterable` pseudo-type function foo(iterable $a)
 { /* */ } $b

    = []; foo($b); class C implements Iterator {} $b = new C; foo($b); PHP 7.1 Features
  48. 162.

    Resources 013: TDD & BDD In PHP 055: Acceptance Testing

    with Behat 017: Modernizing Legacy Codebases in PHP @SammyK #mwphp17 joind.in/talk/82979