SlideShare a Scribd company logo
Standards in
PHP world
About me
Michael Morozov
PHP-developer @ Binary Studio
Coach @ Binary Studio Academy
Submit PHP: Standards in PHP world. Михайло Морозов
World Of Tanks Standards
Standards in PHP
➔ RFC (Requests For Comments)
➔ PSR (PHP Standard Recommendations)
RFC Lifecycle
Internet
Draft
Proposed
Draft
Draft
Standard
Internet
Standard
What about PSR?
PHP Standard Recommendations
➔ Set of conventions aimed to improve collaboration
between different projects in PHP-ecosystem
➔ Established and maintained by
https://github.com/php-fig/fig-standards
PSRs Classification
➔ Accepted
➔ Review
➔ Draft
➔ Deprecated
Deprecated PSR-0
➔ Autoloading Standard
➔ Provided SplClassLoader implementation which is able to load PHP 5.3
classes
'ZendMailMessage' =>
'/path/to/project/lib/vendor/Zend/Mail/Message.php',
'Zend_Config_Json' =>
'/path/to/project/lib/vendor/Zend/Config/Json.php'
Accepted PSRs
Accepted PSR-d+
➔ PSR-1: Basic Coding Standard
➔ PSR-2: Coding Style Guide
➔ PSR-3: Logger Interface
➔ PSR-4: Autoloading Standard
➔ PSR-6: Caching Interface
➔ PSR-7: HTTP Message Interface
Coding
Style
Submit PHP: Standards in PHP world. Михайло Морозов
Code Style Holy Wars. Indentation
Code Style Holy Wars. Case
Code Style Holy Wars. Line Feeds
n or r or rn
Code Style Holy Wars. Right margin
80? 120?
3 screens?
80? 120?
Code Style Holy Wars. Eto translit, detka
$koli4estvo = 10;
$privet = 'Medved';
$Beschleunigung = 9.8;
PSR-1 & PSR-2 Intention
Reduce the cognitive friction when reading code
from other authors by standardized formatting.”
Coding Style Tools
➔ Ourselves
➔ PHP-CS-Fixer (https://github.com/FriendsOfPHP/PHP-CS-Fixer)
➔ PHP_CodeSniffer (https://github.com/squizlabs/PHP_CodeSniffer)
➔ PHP Mess Detector (https://phpmd.org/)
➔ phpcf (https://github.com/badoo/phpcf)
➔ StyleCI (https://styleci.io/)
➔ Our own implementation
PHP-CS-Fixer
➔ CLI utility
➔ Easy to integrate with code editor or CI
➔ Default fixers preset (psr1, psr2, symfony)
➔ Dry-run
➔ Extendability
How about to refine this ?
<?php namespace Submit; class DirtyClass {
private $privacy; protected $data;
public function __construct() {} public function getPrivacy()
{ return $this->privacy;}
}
OK, Let’s run:
$ php php-cs-fixer.phar fix /path/to/dir
<?php namespace Submit;
class FixMe
{
private $privacy;
protected $data;
public function __construct()
{
}
public function getPrivacy()
{
return $this->privacy;
}
}
PHP-CS-Fixer
Custom config
(.php_cs)
$finder = SymfonyCSFinderDefaultFinder::create()
->in('src')
->notPath('tests');
$config = SymfonyCSConfigConfig::create();
$config->level(null);
$config->fixers(
array(
'line_after_namespace',
'linefeed',
'php_closing_tag',
'short_array_syntax',
'unused_use'
)
);
$config->finder($finder);
return $config;
PHP-CS-Fixer as a separate CI ?
https://styleci.io/
What about legacy?
Code style in legacy code
➔ Skip vendor and legacy libs in code style tools
➔ Request single codebase re-formatting
➔ Force every team member using the same style
PSR-3: The “Right” Logging
PSR-3 Logger Interface
namespace PsrLog;
interface LoggerInterface
{
public function emergency($message, array $context = array());
public function alert($message, array $context = array());
public function critical($message, array $context = array());
public function error($message, array $context = array());
public function warning($message, array $context = array());
public function notice($message, array $context = array());
public function info($message, array $context = array());
public function debug($message, array $context = array());
public function log($level, $message, array $context = array());
}
Log All The Things with Monolog
$ composer require monolog/monolog
➔ Fully PSR-3 Compatible
➔ Write to files, sockets, chats, databases, web-services, mails
➔ Customize log format
➔ 42.3 M downloads. Just give it a try.
Monolog
Example
$bindings = [
'slack.handler' => function($app) {
return new MonologHandlerSlackHandler(
getenv('SLACK_TOKEN'),
getenv('SLACK_ROOM')
);
},
'slack.logger' => function($app) {
return new MonologLogger('slack', [$app['slack.handler']]);
}
];
$container = new PimpleContainer($bindings);
$container['slack.logger']->info('Hey, guys!');
$container['slack.logger']->emergency('Website is down!');
PSR-3 Based Loggers
➔ Monolog (https://github.com/Seldaek/monolog)
➔ zend-log (https://github.com/zendframework/zend-log)
➔ KLogger (https://github.com/katzgrau/klogger)
➔ Your logger implementation
➔ Oh, cmon. Just use Monolog
PSR-4 Auto
PSR-4 Autoloading
➔ Autoloading takes care about classes with fully-qualified class names
(FQCN)
➔ Classes, interfaces, traits considers as “class” (FooInterface::class)
<NamespaceName>(<SubNamespaceNames>)*<ClassName>
FQCN Namespace
prefix
Base directory Resulting file path
SymfonyCoreRequest SymfonyCore ./vendor/Symfony/Core/ ./vendor/Symfony/Core/Request.php
AuraWebResponseStatus AuraWeb /path/to/aura-web/src/ /path/to/aura-web/src/Response/Status.php
PSR-4 Autoloading via Composer
{
"autoload": {
"psr-4": {
"Monolog": "src/",
"VendorNamespace": ""
}
}
}
{
"autoload": {
"psr-4": { "": "src/" }
}
}
HTTP
Message
Interface
PSR-7 Main Concept
HTTP Requests and Responses
are abstracted in form of HTTP
messages
PSR-7 Interfaces schema
PSR-7 Component features
➔ Request, ServerRequest, Response, Uri are immutable
➔ Response Body is stream (like php://temp)
PSR-7 Known Implementations
➔ guzzlehttp/psr7 (https://packagist.org/packages/guzzlehttp/psr7)
➔ slim/http (https://packagist.org/packages/slim/http)
➔ zendframework/diactorous
(https://packagist.org/packages/zendframework/zend-diactoros)
➔ wandu/http (https://packagist.org/packages/wandu/http)
➔ symfony/psr-http-message-bridge
(https://packagist.org/packages/symfony/psr-http-message-bridge)
➔ zendframework/zend-psr7-bridge
(https://packagist.org/packages/zendframework/zend-psr7bridge)
PSR-7 examples
$app = new SlimApp;
$app->get('/foo', function ($req, $res, $args) {
return $res->withHeader(
'Content-Type',
'application/json'
);
});
$app->run();
PSR-7 examples
$response = new ZendDiactorosResponse();
$response->getBody()->write("Hellon");
$response->getBody()->write("worldn");
$response = $response
->withHeader('Content-Type', 'text/plain')
->withAddedHeader('X-Show-Something', 'something');
Caching with PSR-6
Submit PHP: Standards in PHP world. Михайло Морозов
PSR-6: Caching interface
CacheItemPool
CacheItem
Caching examples using Stash (tedivm/stash)
$driver = new StashDriverFileSystem();
$pool = new StashPool($driver);
$item = $pool->getItem('path/to/data');
$info = $item->get();
if ($item->isMiss()) {
$info = loadInfo($id);
$item->set($userInfo, 120);
}
return $info;
Cache implementations
https://packagist.org/providers/psr/cache-implementation
Interesting Draft
PSRs
Draft PSRs
➔ PSR-12: Extended Coding Style Guide
➔ PSR-14: Event Manager
➔ PSR-15: HTTP Middlewares
Current Stage and Future of PHP-FIG
➔ Some members complained that they are forced to use or support
PSRs in their projects
➔ As a results they would like to have some “re-branding”
➔ This led to PHP Community-driven Standards and HTTP Interop
appearing
Summary
➔ Following coding standards disciplines & improves readability
➔ Sometimes usage of “code-smell” tools is beneficial and not routine
➔ Autoloading via Composer nowadays rocks
➔ There are some well-grounded techniques that can be a problem solution
(logging, caching, containers, etc.)
➔ Having abstraction layer in HTTP is more convenient than raw access to
superglobals
➔ PHP becomes more mature and more standardized
Questions ?
Thanks for
watching

More Related Content

PPTX
Php’s guts
PPT
Hacking with hhvm
PDF
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
PDF
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
PDF
Zend expressive workshop
PDF
Demystifying Object-Oriented Programming - ZendCon 2016
PDF
Bringing modern PHP development to IBM i (ZendCon 2016)
Php’s guts
Hacking with hhvm
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Zend expressive workshop
Demystifying Object-Oriented Programming - ZendCon 2016
Bringing modern PHP development to IBM i (ZendCon 2016)

What's hot (20)

PPT
typemap in Perl/XS
PDF
PECL Picks - Extensions to make your life better
ODP
30 Minutes To CPAN
PPT
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
PPT
On UnQLite
PPTX
Php 7 hhvm and co
ODP
Php in 2013 (Web-5 2013 conference)
PPT
Composer - Package Management for PHP. Silver Bullet?
PDF
Continuous Quality Assurance
PDF
Debugging on rails
PDF
Apache and PHP: Why httpd.conf is your new BFF!
PDF
Lecture8
PDF
Shellcode Analysis - Basic and Concept
PPTX
PHP from soup to nuts Course Deck
ODP
Deploying Perl apps on dotCloud
PPTX
PHP Function
PPTX
PHP 7 Crash Course - php[world] 2015
PDF
Mysqlnd, an unknown powerful PHP extension
PDF
Gradle in a Polyglot World
PDF
How DSL works on Ruby
typemap in Perl/XS
PECL Picks - Extensions to make your life better
30 Minutes To CPAN
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
On UnQLite
Php 7 hhvm and co
Php in 2013 (Web-5 2013 conference)
Composer - Package Management for PHP. Silver Bullet?
Continuous Quality Assurance
Debugging on rails
Apache and PHP: Why httpd.conf is your new BFF!
Lecture8
Shellcode Analysis - Basic and Concept
PHP from soup to nuts Course Deck
Deploying Perl apps on dotCloud
PHP Function
PHP 7 Crash Course - php[world] 2015
Mysqlnd, an unknown powerful PHP extension
Gradle in a Polyglot World
How DSL works on Ruby
Ad

Similar to Submit PHP: Standards in PHP world. Михайло Морозов (20)

PPTX
PSR: Standards in PHP by Alex Simanovich
PPTX
The World of PHP PSR Standards
PDF
PSR-7 - HTTP message interfaces
PDF
PSR-7 and PSR-15, why can't you ignore them
PPTX
An intro to php standards recommendation (psr)
PDF
Meet up symfony 16 juin 2017 - Les PSR
PDF
PHP Standards Recommendations - PHP-FIG
PDF
Make your application expressive
PDF
PPTX
Php psr standard 2014 01-22
PPT
PHP-FIG: Past, Present and Future
PDF
Composer Helpdesk
PDF
Current status of PSR - Phpblt1
PDF
Introducción a aplicaciones php basadas en middleware y psr 7
PDF
Coding standards PSR-1 & PSR-2
PDF
Making the Most of Modern PHP in Drupal 7
PDF
Zend Expressive 3 e PSR-15
PPTX
Composer namespacing
PDF
Zend/Expressive 3 – The Next Generation
PDF
PSR-7, middlewares e o futuro dos frameworks
PSR: Standards in PHP by Alex Simanovich
The World of PHP PSR Standards
PSR-7 - HTTP message interfaces
PSR-7 and PSR-15, why can't you ignore them
An intro to php standards recommendation (psr)
Meet up symfony 16 juin 2017 - Les PSR
PHP Standards Recommendations - PHP-FIG
Make your application expressive
Php psr standard 2014 01-22
PHP-FIG: Past, Present and Future
Composer Helpdesk
Current status of PSR - Phpblt1
Introducción a aplicaciones php basadas en middleware y psr 7
Coding standards PSR-1 & PSR-2
Making the Most of Modern PHP in Drupal 7
Zend Expressive 3 e PSR-15
Composer namespacing
Zend/Expressive 3 – The Next Generation
PSR-7, middlewares e o futuro dos frameworks
Ad

More from Binary Studio (20)

PPTX
Academy PRO: D3, part 3
PPTX
Academy PRO: D3, part 1
PPTX
Academy PRO: Cryptography 3
PPTX
Academy PRO: Cryptography 1
PPTX
Academy PRO: Advanced React Ecosystem. MobX
PPTX
Academy PRO: Docker. Part 4
PPTX
Academy PRO: Docker. Part 2
PPTX
Academy PRO: Docker. Part 1
PPTX
Binary Studio Academy 2017: JS team project - Orderly
PPTX
Binary Studio Academy 2017: .NET team project - Unicorn
PPTX
Academy PRO: React native - miscellaneous
PPTX
Academy PRO: React native - publish
PPTX
Academy PRO: React native - navigation
PPTX
Academy PRO: React native - building first scenes
PPTX
Academy PRO: React Native - introduction
PPTX
Academy PRO: Push notifications. Denis Beketsky
PPTX
Academy PRO: Docker. Lecture 4
PPTX
Academy PRO: Docker. Lecture 3
PPTX
Academy PRO: Docker. Lecture 2
PPTX
Academy PRO: Docker. Lecture 1
Academy PRO: D3, part 3
Academy PRO: D3, part 1
Academy PRO: Cryptography 3
Academy PRO: Cryptography 1
Academy PRO: Advanced React Ecosystem. MobX
Academy PRO: Docker. Part 4
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 1
Binary Studio Academy 2017: JS team project - Orderly
Binary Studio Academy 2017: .NET team project - Unicorn
Academy PRO: React native - miscellaneous
Academy PRO: React native - publish
Academy PRO: React native - navigation
Academy PRO: React native - building first scenes
Academy PRO: React Native - introduction
Academy PRO: Push notifications. Denis Beketsky
Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 1

Recently uploaded (20)

PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
AI in Product Development-omnex systems
PPTX
Introduction to Artificial Intelligence
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Nekopoi APK 2025 free lastest update
PPTX
Transform Your Business with a Software ERP System
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Understanding Forklifts - TECH EHS Solution
Design an Analysis of Algorithms II-SECS-1021-03
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia
AI in Product Development-omnex systems
Introduction to Artificial Intelligence
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Nekopoi APK 2025 free lastest update
Transform Your Business with a Software ERP System
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
How to Migrate SBCGlobal Email to Yahoo Easily
Odoo POS Development Services by CandidRoot Solutions
Design an Analysis of Algorithms I-SECS-1021-03
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Reimagine Home Health with the Power of Agentic AI​
Wondershare Filmora 15 Crack With Activation Key [2025
Operating system designcfffgfgggggggvggggggggg
Understanding Forklifts - TECH EHS Solution

Submit PHP: Standards in PHP world. Михайло Морозов

  • 2. About me Michael Morozov PHP-developer @ Binary Studio Coach @ Binary Studio Academy
  • 4. World Of Tanks Standards
  • 5. Standards in PHP ➔ RFC (Requests For Comments) ➔ PSR (PHP Standard Recommendations)
  • 8. PHP Standard Recommendations ➔ Set of conventions aimed to improve collaboration between different projects in PHP-ecosystem ➔ Established and maintained by https://github.com/php-fig/fig-standards
  • 9. PSRs Classification ➔ Accepted ➔ Review ➔ Draft ➔ Deprecated
  • 10. Deprecated PSR-0 ➔ Autoloading Standard ➔ Provided SplClassLoader implementation which is able to load PHP 5.3 classes 'ZendMailMessage' => '/path/to/project/lib/vendor/Zend/Mail/Message.php', 'Zend_Config_Json' => '/path/to/project/lib/vendor/Zend/Config/Json.php'
  • 12. Accepted PSR-d+ ➔ PSR-1: Basic Coding Standard ➔ PSR-2: Coding Style Guide ➔ PSR-3: Logger Interface ➔ PSR-4: Autoloading Standard ➔ PSR-6: Caching Interface ➔ PSR-7: HTTP Message Interface
  • 15. Code Style Holy Wars. Indentation
  • 16. Code Style Holy Wars. Case
  • 17. Code Style Holy Wars. Line Feeds n or r or rn
  • 18. Code Style Holy Wars. Right margin 80? 120? 3 screens? 80? 120?
  • 19. Code Style Holy Wars. Eto translit, detka $koli4estvo = 10; $privet = 'Medved'; $Beschleunigung = 9.8;
  • 20. PSR-1 & PSR-2 Intention Reduce the cognitive friction when reading code from other authors by standardized formatting.”
  • 21. Coding Style Tools ➔ Ourselves ➔ PHP-CS-Fixer (https://github.com/FriendsOfPHP/PHP-CS-Fixer) ➔ PHP_CodeSniffer (https://github.com/squizlabs/PHP_CodeSniffer) ➔ PHP Mess Detector (https://phpmd.org/) ➔ phpcf (https://github.com/badoo/phpcf) ➔ StyleCI (https://styleci.io/) ➔ Our own implementation
  • 22. PHP-CS-Fixer ➔ CLI utility ➔ Easy to integrate with code editor or CI ➔ Default fixers preset (psr1, psr2, symfony) ➔ Dry-run ➔ Extendability
  • 23. How about to refine this ? <?php namespace Submit; class DirtyClass { private $privacy; protected $data; public function __construct() {} public function getPrivacy() { return $this->privacy;} } OK, Let’s run: $ php php-cs-fixer.phar fix /path/to/dir
  • 24. <?php namespace Submit; class FixMe { private $privacy; protected $data; public function __construct() { } public function getPrivacy() { return $this->privacy; } }
  • 25. PHP-CS-Fixer Custom config (.php_cs) $finder = SymfonyCSFinderDefaultFinder::create() ->in('src') ->notPath('tests'); $config = SymfonyCSConfigConfig::create(); $config->level(null); $config->fixers( array( 'line_after_namespace', 'linefeed', 'php_closing_tag', 'short_array_syntax', 'unused_use' ) ); $config->finder($finder); return $config;
  • 26. PHP-CS-Fixer as a separate CI ? https://styleci.io/
  • 28. Code style in legacy code ➔ Skip vendor and legacy libs in code style tools ➔ Request single codebase re-formatting ➔ Force every team member using the same style
  • 30. PSR-3 Logger Interface namespace PsrLog; interface LoggerInterface { public function emergency($message, array $context = array()); public function alert($message, array $context = array()); public function critical($message, array $context = array()); public function error($message, array $context = array()); public function warning($message, array $context = array()); public function notice($message, array $context = array()); public function info($message, array $context = array()); public function debug($message, array $context = array()); public function log($level, $message, array $context = array()); }
  • 31. Log All The Things with Monolog $ composer require monolog/monolog ➔ Fully PSR-3 Compatible ➔ Write to files, sockets, chats, databases, web-services, mails ➔ Customize log format ➔ 42.3 M downloads. Just give it a try.
  • 32. Monolog Example $bindings = [ 'slack.handler' => function($app) { return new MonologHandlerSlackHandler( getenv('SLACK_TOKEN'), getenv('SLACK_ROOM') ); }, 'slack.logger' => function($app) { return new MonologLogger('slack', [$app['slack.handler']]); } ]; $container = new PimpleContainer($bindings); $container['slack.logger']->info('Hey, guys!'); $container['slack.logger']->emergency('Website is down!');
  • 33. PSR-3 Based Loggers ➔ Monolog (https://github.com/Seldaek/monolog) ➔ zend-log (https://github.com/zendframework/zend-log) ➔ KLogger (https://github.com/katzgrau/klogger) ➔ Your logger implementation ➔ Oh, cmon. Just use Monolog
  • 35. PSR-4 Autoloading ➔ Autoloading takes care about classes with fully-qualified class names (FQCN) ➔ Classes, interfaces, traits considers as “class” (FooInterface::class) <NamespaceName>(<SubNamespaceNames>)*<ClassName> FQCN Namespace prefix Base directory Resulting file path SymfonyCoreRequest SymfonyCore ./vendor/Symfony/Core/ ./vendor/Symfony/Core/Request.php AuraWebResponseStatus AuraWeb /path/to/aura-web/src/ /path/to/aura-web/src/Response/Status.php
  • 36. PSR-4 Autoloading via Composer { "autoload": { "psr-4": { "Monolog": "src/", "VendorNamespace": "" } } } { "autoload": { "psr-4": { "": "src/" } } }
  • 38. PSR-7 Main Concept HTTP Requests and Responses are abstracted in form of HTTP messages
  • 40. PSR-7 Component features ➔ Request, ServerRequest, Response, Uri are immutable ➔ Response Body is stream (like php://temp)
  • 41. PSR-7 Known Implementations ➔ guzzlehttp/psr7 (https://packagist.org/packages/guzzlehttp/psr7) ➔ slim/http (https://packagist.org/packages/slim/http) ➔ zendframework/diactorous (https://packagist.org/packages/zendframework/zend-diactoros) ➔ wandu/http (https://packagist.org/packages/wandu/http) ➔ symfony/psr-http-message-bridge (https://packagist.org/packages/symfony/psr-http-message-bridge) ➔ zendframework/zend-psr7-bridge (https://packagist.org/packages/zendframework/zend-psr7bridge)
  • 42. PSR-7 examples $app = new SlimApp; $app->get('/foo', function ($req, $res, $args) { return $res->withHeader( 'Content-Type', 'application/json' ); }); $app->run();
  • 43. PSR-7 examples $response = new ZendDiactorosResponse(); $response->getBody()->write("Hellon"); $response->getBody()->write("worldn"); $response = $response ->withHeader('Content-Type', 'text/plain') ->withAddedHeader('X-Show-Something', 'something');
  • 47. Caching examples using Stash (tedivm/stash) $driver = new StashDriverFileSystem(); $pool = new StashPool($driver); $item = $pool->getItem('path/to/data'); $info = $item->get(); if ($item->isMiss()) { $info = loadInfo($id); $item->set($userInfo, 120); } return $info;
  • 50. Draft PSRs ➔ PSR-12: Extended Coding Style Guide ➔ PSR-14: Event Manager ➔ PSR-15: HTTP Middlewares
  • 51. Current Stage and Future of PHP-FIG ➔ Some members complained that they are forced to use or support PSRs in their projects ➔ As a results they would like to have some “re-branding” ➔ This led to PHP Community-driven Standards and HTTP Interop appearing
  • 52. Summary ➔ Following coding standards disciplines & improves readability ➔ Sometimes usage of “code-smell” tools is beneficial and not routine ➔ Autoloading via Composer nowadays rocks ➔ There are some well-grounded techniques that can be a problem solution (logging, caching, containers, etc.) ➔ Having abstraction layer in HTTP is more convenient than raw access to superglobals ➔ PHP becomes more mature and more standardized