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

Modern PHP, Standards, and Community

22f21d5c22b930fd35dd98f25dedf6a4?s=47 Ben Edmunds
January 14, 2016

Modern PHP, Standards, and Community

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

January 14, 2016
Tweet

Transcript

  1. PHP modern standards & Community

  2. Who is this guy? Ben Edmunds @benedmunds http://benedmunds.com

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

    Town Hall Podcast CTO at Mindfulware
  4. Welcome to the Future

  5. Welcome to the Future Exceptions Namespaces Closures

  6. Welcome to the Future Statics PDO Short Arrays Null Coalescing

  7. Legit Tools

  8. Legit Tools Built-in Server Unit Testing Composer

  9. Standards

  10. Standards PHP-FIG PSRs

  11. Community

  12. Community Twitter etc User Groups

  13. Welcome to the Future

  14. Great Scott!

  15. Exceptions

  16. None
  17. Exceptions try { //your code goes here } catch (Exception

    $e) { die($e->getMessage()); }
  18. Exceptions try { //your code goes here } catch (Exception

    $e) { die($e->getMessage()); }
  19. Closures

  20. None
  21. Closures Route::get(‘/', function(){ return View::make(‘index'); });

  22. Closures Route::get(‘/', function(){ return View::make(‘index'); });

  23. Namespaces

  24. None
  25. Namespaces namespace Illuminate\Console; class Command { //…

  26. Namespaces use Illuminate\Console\Command; namespace Illuminate\Console; class Command { //…

  27. Namespaces use Illuminate\Console\Command; namespace Illuminate\Console; class Command { //…

  28. Statics

  29. None
  30. Statics Class Route { public static function get() { //…

    }
  31. Statics Route::get(); Class Route { public static function get() {

    //… }
  32. Statics Route::get(); Class Route { public static function get() {

    //… }
  33. Statics NO $this $var = self::varAtDefinition; $var = static::varAtExec;

  34. Short Array Syntax

  35. None
  36. Short Array Syntax $array = array( 0 => ‘value1’, 1

    => ‘value2’, );
  37. Short Array Syntax $array = [ 0 => ‘value1’, 1

    => ‘value2’, ];
  38. Short Array Syntax $array = [ 0 => ‘value1’, 1

    => ‘value2’, ];
  39. Null Coalescing Operator

  40. Null Coalescing $val = $_GET['val'] ?? 'default';

  41. Null Coalescing $val = $_GET['val'] ?? 'default';

  42. Null Coalescing $val = isset($_GET[‘val’]) ? $_GET[‘val’] : 'default';

  43. Traits

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

    function getName() { return ‘Jon Snow’; } }
  45. Traits class adminUser { use baseUser; }

  46. Traits $adminUser = new adminUser; echo $adminUser->getName(); //output = ‘Jon

    Snow’
  47. PDO

  48. None
  49. PDO Cross System

  50. PDO Cross System MS SQL MySQL Oracle PostgreSQL SQLite CUBRID

    Firebird Informix ODBC & DB2 4D
  51. PDO Cross System Safe Binding

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

    ’); $stmt->bindParam(‘:id’, $id); $stmt->execute();
  53. Legit Tools

  54. None
  55. Built-in Web Server

  56. Built-in Server $ php -S localhost:8000 PHP 5.4.0 Development Server

    started… Listening on localhost:8000 Document root is /home/ben/htdocs Press Ctrl-C to quit
  57. Composer

  58. Another Package Manager!?

  59. Composer Sane Package Management

  60. Composer Autoloading

  61. Composer PEAR, ha! packagist.org

  62. Composer / composer.json { "require": { "stripe/stripe-php": "dev-master", "twilio/sdk": "dev-master"

    } }
  63. Composer $ php composer.phar update $ php composer.phar install

  64. Composer $client = new Services_Twilio($sid, $tkn); $client->account ->messages ->sendMessage(…)

  65. Unit Testing

  66. None
  67. Unit Testing PHPUnit Behat Mink Selenium CodeCeption PHPSpec

  68. Unit Testing class ApiAuthTest extends PHPUnit_Framework_TestCase { public function testVerify()

    { $auth = new apiAuth(); $this->assertTrue($auth->verify());
  69. Unit Testing class ApiAuthTest extends PHPUnit_Framework_TestCase { public function testVerify()

    { $auth = new apiAuth(); $this->assertTrue($auth->verify());
  70. Unit Testing $ phpunit tests PHPUnit 3.3.17 by Sebastian Bergmann.

    Time: 0.01 seconds OK (1 tests, 1 assertions)
  71. Standards

  72. None
  73. Standards PHP-FIG Framework Interop Group

  74. Standards Member Projects Zend Symfony CakePHP Laravel SugarCRM Drupal

  75. Standards PSRs PHP Standards Recommendation

  76. Standards PSRs Autoloading Interfaces Style Guides

  77. 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
  78. Standards PSR-4 Auto-loading Replaces PSR-0 Used by Composer

  79. Standards $client = new Services_Twilio($sid, $tkn); $client->account ->messages ->sendMessage(…)

  80. Standards PSR-1 Basic Coding Styles Generally accepted Not very opinionated

  81. Standards PSR-1 Basic Coding Styles camelCasing Opening Tags Namespacing Class

    Names UTF-8
  82. Standards PSR-2 Coding Style Guide Greater Detail Opinionated

  83. Standards PSR-2 Coding Style Guide Spacing Braces Lines Keywords Bools

    Control Struct
  84. Standards PSR-7 HTTP Message Interface Requests Responses

  85. Community

  86. None
  87. Community Open Inviting Genuine

  88. Community Twitter @phpc https://twitter.com/CalEvans /lists/phpeople Framework / Project

  89. Community Mailing List http://php.net/mailing-lists.php

  90. Community IRC Freenode #phpc ##php

  91. Community Blogs PlanetPHP php[architect]

  92. Community Podcasts PHP Roundtable PHP Townhall Voices of the ElePHPant

  93. Community Local User Group Nearest Large City Start It!

  94. Community Conferences Hallway Track Dinner Drinks Hotel Lobby

  95. Resources

  96. None
  97. Resources PHP.net

  98. Resources Modern Frameworks Laravel Symfony2 Fuel PHP SlimPHP 2 Aura

    for PHP Silex
  99. Resources leanpub.com/ phptherightway PHPtheRightWay.com

  100. Resources BuildSecurePHPapps.com Coupon Code: skiphp $10 off http://buildsecurephpapps.com/?coupon=skiphp

  101. Q/A TIME! Ben Edmunds @benedmunds http://benedmunds.com http://buildsecurephpapps.com/?coupon=skiphp https://joind.in/talk/aedbd