Modern PHP, Standards, and Community (phpDay 2017)

Modern PHP, Standards, and Community (phpDay 2017)

Learn how to structure and maintain a modern day PHP project using the latest standards. We'll walk through recent language improvements and how they will affect your day to day development. This will use code examples to give you in depth, real world examples of usage.

We'll also cover the latest community initiatives and standards including the PHPFIG along with the PSRs they have introduced.

22f21d5c22b930fd35dd98f25dedf6a4?s=128

Ben Edmunds

May 19, 2017
Tweet

Transcript

  1. 3.

    Who is this guy? Ben Edmunds Open Source Author PHP

    Town Hall Podcast CTO at Mindfulware
  2. 11.
  3. 13.
  4. 18.
  5. 23.

    Errors try { //error thrown here } catch (Error $e)

    { die($e->getMessage()); } catch (Exception $e) { die($e->getMessage()); }
  6. 24.

    Errors try { //err or excpt thrown here } catch

    (Throwable $t) { die($t->getMessage()); }
  7. 25.

    PDO

  8. 26.
  9. 30.

    PDO $stmt = $db->prepare(‘ SELECT * FROM users WHERE id=:id

    ’); $stmt->bindParam(‘:id’, $id); $stmt->execute();
  10. 31.
  11. 32.
  12. 36.
  13. 41.
  14. 45.
  15. 46.

    Traits // grouping without // strict inheritance trait baseUser {

    function getName() { return ‘Jon Snow’; } }
  16. 49.
  17. 53.

    Passwords if (password_verify($_POST['pass'], $u->pass)) { if (password_needs_rehash( $u->pass, PASSWORD_DEFAULT ))

    { $u->pass = password_hash( $_POST['pass'], PASSWORD_DEFAULT ); $u->save();
  18. 58.
  19. 59.
  20. 62.

    Scalar Types declare(strict_types=1); function addNums(float $a, float $b) { return

    $a + $b; } addNums(2, "1 week"); // Fatal error: Uncaught TypeError: Argument 2 passed to addNums() must be of the type float, string given
  21. 63.

    Scalar Types function addNums(float $a, float $b) addNums(2, "1 week”);

    // Fatal error: Uncaught TypeError: Argument 2 passed to addNums() must be of the type float, string given
  22. 70.

    Scalar Types function addNums($a, $b) : int { return $a

    + $b; } addNums(1.5, 1); // Fatal error: Uncaught TypeError: Return value of addNums() must be of the type integer, float returned
  23. 72.
  24. 74.

    Built-in Server $ php -S localhost:8000 PHP 5.7.0 Development Server

    started… Listening on localhost:8000 Document root is /home/ben/htdocs Press Ctrl-C to quit
  25. 75.
  26. 87.
  27. 89.
  28. 90.
  29. 91.

    Unit Testing $ phpunit tests PHPUnit 3.3.17 by Sebastian Bergmann.

    Time: 0.01 seconds OK (1 tests, 1 assertions)
  30. 92.
  31. 93.
  32. 98.

    Standards PSRs PSR-4: Autoloading PSR-1: Basic Coding Standards PSR-2: Coding

    Style Guide PSR-7: HTTP Message Interface PSR-6: Caching Interface PSR-3: Logger Interface
  33. 106.
  34. 107.
  35. 117.

    Q/A

  36. 118.
  37. 119.