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

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.

Sammy Kaye Powers

March 17, 2017

More Decks by Sammy Kaye Powers

Other Decks in Programming


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

    No automated tests • Has outdated dependencies • No autoloading • No sign of “single responsibility”
  2. “Legacy” We’ll assume …means any code that can be improved

    (at least for this talk) @SammyK #mwphp17 joind.in/talk/82979
  3. 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)
  4. Consider the Stakeholders I’ll need 80 hours to refactor the

    user auth & ACL @SammyK #mwphp17 joind.in/talk/82979
  5. Consider the Stakeholders • Most critical security holes • Most

    critical bugs • Most critical features • Use data from static analysis Make a plan
  6. Kickass Development Environments with Docker David McKay Tomorrow @ 11

    AM in Ballroom D @SammyK #mwphp17 joind.in/talk/82979
  7. 7.1

  8. PHP 7 Quick tricks to refactor to (in order of

    ease) @SammyK #mwphp17 joind.in/talk/82979
  9. PHP 7.0 “Gotchas” Another bird with the PHP 7.0 stone

    ext/mssql functions instead use sqlsrv_*(), odbc_*(), PDO
  10. PHP 7.0 “Gotchas” Uniform Variable Syntax Change in evaluating indirect

    expressions @SammyK #mwphp17 joind.in/talk/82979
  11. 7.x

  12. 5.x

  13. 5.x

  14. 7.x

  15. 7.x

  16. 7.x

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

    line 6 Notice: Undefined variable: Array in / foo.php on line 6
  18. PHP 7.0 Features Scalar Type Declarations function foo(string $name,

 bool $isGreat,
 float $income)
 { /* */ }
  19. PHP 7.0 Features Scalar Type Declarations function foo(string $name,

 bool $isGreat,
 float $income)
 { /* */ }
  20. PHP 7.0 Features $bar = isset($_GET[‘foo’]) ? $_GET[‘foo’] : null;

    Null coalesce operator $bar = $_GET[‘foo’] ?? null;
  21. Class constant visibility class Foo {
 public const FOO =

    0; protected const BAR = 1; private const BAZ = 2; } PHP 7.1 Features
  22. `iterable` pseudo-type function foo(iterable $a)
 { /* */ } $b

    = []; foo($b); class C implements Iterator {} $b = new C; foo($b); PHP 7.1 Features
  23. Resources 013: TDD & BDD In PHP 055: Acceptance Testing

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