$30 off During Our Annual Pro Sale. View Details »

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.

Ben Edmunds

May 19, 2017
Tweet

More Decks by Ben Edmunds

Other Decks in Technology

Transcript

  1. Who is this guy? Ben Edmunds Open Source Author PHP

    Town Hall Podcast CTO at Mindfulware
  2. Errors try { //error thrown here } catch (Error $e)

    { die($e->getMessage()); } catch (Exception $e) { die($e->getMessage()); }
  3. Errors try { //err or excpt thrown here } catch

    (Throwable $t) { die($t->getMessage()); }
  4. PDO

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

    ’); $stmt->bindParam(‘:id’, $id); $stmt->execute();
  6. Traits // grouping without // strict inheritance trait baseUser {

    function getName() { return ‘Jon Snow’; } }
  7. 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();
  8. 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
  9. 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
  10. 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
  11. 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
  12. Unit Testing $ phpunit tests PHPUnit 3.3.17 by Sebastian Bergmann.

    Time: 0.01 seconds OK (1 tests, 1 assertions)
  13. 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
  14. Q/A