Bringing Old Legacy Apps To PHP 7 and Beyond - ZendCon 2016

Bringing Old Legacy Apps To PHP 7 and Beyond - ZendCon 2016

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 or a web app written years ago on a now-defunct web framework. The initial temptation might be, "I'll just rewrite all this in x framework." But hold on my framework friend, a rewrite is costly and is rarely the correct answer. We'll discuss strategies to give that legacy codebase a complete makeover in PHP 7 with incremental changes that keep the business running while improving security, stability, and maintainability of the codebase.

8c090cc1ccd623a146ddd9159b1bf7e2?s=128

Sammy Kaye Powers

October 19, 2016
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

    @SammyK #zendcon2016 joind.in/talk/6d127 (at least for this talk)
  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 #zendcon2016 joind.in/talk/6d127
  10. 29.

    Consider the Stakeholders • Most critical security holes • Most

    critical bugs • Most critical features • Use data from static analysis Make a plan
  11. 36.
  12. 40.

    7.0

  13. 48.

    PHP 7.0 Quick tricks to refactor to (in order of

    ease) @SammyK #zendcon2016 joind.in/talk/6d127
  14. 49.

    PHP 7.0 “Gotchas” ASP and script PHP tags removed <%

    %> <%= %> <script language="php"></script>
  15. 55.

    PHP 7.0 “Gotchas” “There’s a shim for that!” ereg* functions

    bbrala/php7-ereg-shim eregi($pattern, $sub, &$match) preg_match('/'.$pattern.'/i', $sub, $match)
  16. 59.

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

    ext/mssql functions instead use sqlsrv_*(), odbc_*(), PDO
  17. 60.
  18. 62.
  19. 63.

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

    expressions @SammyK #zendcon2016 joind.in/talk/6d127
  20. 65.

    PHP 7.0 “Gotchas” Uniform Variable Syntax $foo = ['bar' =>

    ['baz' => ‘apple']]; $apple = 'PHP 5.x I see...'; var_dump($$foo['bar']['baz']); string(16) "PHP 5.x I see..." 5.x
  21. 66.

    PHP 7.0 “Gotchas” Uniform Variable Syntax Notice: Array to string

    conversion in / foo.php on line 6 Notice: Undefined variable: Array in / foo.php on line 6 7.x
  22. 88.
  23. 91.
  24. 95.
  25. 106.

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

    $age,
 bool $isGreat,
 float $income)
 { /* */ }
  26. 107.

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

    $age,
 bool $isGreat,
 float $income)
 { /* */ }
  27. 111.
  28. 114.

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

    Null coalesce operator $bar = $_GET[‘foo’] ?? null;
  29. 128.

    Class constant visibility class Foo {
 public const FOO =

    0; protected const BAR = 1; private const BAZ = 2; } PHP 7.1 considerations
  30. 130.

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

    7.1 considerations $b = []; foo($b); class C implements Iterator {} $b = new C; foo($b);
  31. 143.

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

    with Behat 017: Modernizing Legacy Codebases in PHP November 3rd @ 12:00PM CDT