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

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.

Sammy Kaye Powers

October 19, 2016
Tweet

More Decks by Sammy Kaye Powers

Other Decks in Programming

Transcript

  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

    @SammyK #zendcon2016 joind.in/talk/6d127 (at least for this talk)
  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 #zendcon2016 joind.in/talk/6d127
  5. Consider the Stakeholders • Most critical security holes • Most

    critical bugs • Most critical features • Use data from static analysis Make a plan
  6. 7.0

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

    ease) @SammyK #zendcon2016 joind.in/talk/6d127
  8. PHP 7.0 “Gotchas” ASP and script PHP tags removed <%

    %> <%= %> <script language="php"></script>
  9. 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)
  10. PHP 7.0 “Gotchas” Another bird with the PHP 7.0 stone

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

    expressions @SammyK #zendcon2016 joind.in/talk/6d127
  12. 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
  13. 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
  14. PHP 7.0 Features Scalar Type Declarations function foo(string $name,
 int

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

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

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

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

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

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