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

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

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

Talk given at Pacific Northwest 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

September 09, 2017

More Decks by Sammy Kaye Powers

Other Decks in Programming


  1. joind.in/talk/228f1 @SammyK #pnwphp “Legacy” /leɡəsē/ • Requires an EOL version

    of PHP • No automated tests • Has outdated dependencies • No autoloading • No sign of “single responsibility”
  2. joind.in/talk/228f1 @SammyK #pnwphp 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)
  3. joind.in/talk/228f1 @SammyK #pnwphp Consider the Stakeholders • Most critical security

    holes • Most critical bugs • Most critical features • Use data from static analysis Make a plan
  4. 7.1

  5. joind.in/talk/228f1 @SammyK #pnwphp PHP 7.0 “Gotchas” “There’s a shim for

    that!” ereg* functions bbrala/php7-ereg-shim (Björn Brala)
  6. PHP 7.0 “Gotchas” Another bird with the PHP 7.0 stone

    ext/mssql functions instead use sqlsrv_*(), odbc_*(), PDO
  7. 7.x

  8. joind.in/talk/228f1 @SammyK #pnwphp 7.x Notice: Array to string conversion in

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

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

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

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

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

    = []; foo($b); class C implements Iterator {} $b = new C; foo($b); PHP 7.1 Features
  14. Env vars aren’t designed for secrets (shared with child processes,

    etc) Error messages can contain dump of env vars (filp/whoops)
  15. joind.in/talk/228f1 @SammyK #pnwphp Create a PHP application without a framework

    https://github.com/PatrickLouys/no-framework-tutorial Patrick Louys
  16. joind.in/talk/228f1 @SammyK #pnwphp Resources 013: TDD & BDD In PHP

    055: Acceptance Testing with Behat 017: Modernizing Legacy Codebases in PHP