SlideShare ist ein Scribd-Unternehmen logo
1 von 23
PSR: Standards in PHP
Story
PHP Standards for Writing Code
PEAR
Zend Framework
Drupal
Mine standards
… etc
Framework Interoperability Group - FIG
◦ Michael Dowling (AWS SDK for PHP)
◦ Larry Masters (CakePHP)
◦ Guilherme Blanco (Doctrine)
◦ Larry Garfield (Drupal)
◦ Filipe Guerra (SugarCRM)
◦ Bernhard Schussek (Symfony2)
◦ Alexander Makarov (Yii framework)
◦ Pádraic Brady (Zend Framework 2)
FIG’s Goal
The goal of the FIG is to create a dialogue
between project representatives, with the
aim of finding ways to work together
(interoperability)
PSR-0
AUTOLOADER STANDARD
Tools
require() in PHP 4
__autoload() in PHP 5
spl_autoload() and spl_autoload_register() in PHP 5.1.2
Requirements
◦ A fully-qualified namespace and class must have the following structure
<Vendor Name>(<Namespace>)*<Class Name>
◦ Each namespace must have a top-level namespace ("Vendor Name").
◦ Each namespace can have as many sub-namespaces as it wishes.
◦ Each namespace separator is converted to a DIRECTORY_SEPARATOR when loading from the file system.
◦ Each _ character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. The _ character has no
special meaning in the namespace.
◦ The fully-qualified namespace and class is suffixed with .php when loading from the file system.
◦ Alphabetic characters in vendor names, namespaces, and class names may be of any combination of
lower case and upper case.
Example
◦ DoctrineCommonIsolatedClassLoader =>
/path/to/project/lib/vendor/Doctrine/Common/IsolatedClassLoader.php
◦ SymfonyCoreRequest => /path/to/project/lib/vendor/Symfony/Core/Request.php
◦ ZendAcl => /path/to/project/lib/vendor/Zend/Acl.php
◦ ZendMailMessage => /path/to/project/lib/vendor/Zend/Mail/Message.php
◦ namespacepackageClass_Name =>
/path/to/project/lib/vendor/namespace/package/Class/Name.php
◦ namespacepackage_nameClass_Name =>
/path/to/project/lib/vendor/namespace/package_name/Class/Name.php
PSR-0: not for PHP core
PSR-1
BASIC CODING STANDARD
Basic Coding Standard
◦ Only use the <?php and <?= tags.
◦ Only use UTF-8 without BOM for PHP code.
◦ Separate side-effects (generate output, access a database etc.) and declarations.
◦ Enforce PSR-0.
◦ Class names must be defined in StudlyCaps.
◦ Class constants must be defined in upper case with underscore separators.
◦ Method names must be defined in camelCase.
PSR-2
CODING STYLE GUIDE
Coding Style Guide
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
PSR-3
LOGGER INTERFACE
Logger Interface
◦ The LoggerInterface exposes eight methods to write logs to the eight RFC 5424 levels (debug, info,
notice, warning, error, critical, alert, emergency)
◦ A ninth method, log, accepts a log level as first argument. Calling this method with one of the log level
constants MUST have the same result as calling the level-specific method. Calling this method with a
level not defined by this specification MUST throw a PsrLogInvalidArgumentException if the
implementation does not know about the level. Users SHOULD NOT use a custom level without knowing
for sure the current implementation supports it.
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
PSR-4 (PSR-0 extension)
IMPROVED AUTOLOADING
PSR-0 way
PSR-4 way
Criticism
Often hear
Too far
Subjective
Too specific
Not flexible
Become PHP-FIG community member
https://groups.google.com/forum/#!forum/php-fig
Thanks
• Email: ax.simanovich@gmail.com
• Skype: aliaksandr.simanovich
• Twitter: @simanjan
• Blog: simanovich.info

Weitere ähnliche Inhalte

Was ist angesagt?

Lifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeLifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeAlexander Shopov
 
Chapter1pp
Chapter1ppChapter1pp
Chapter1ppJ. C.
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Languagezone
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming LanguageRaghavan Mohan
 
ADA programming language
ADA programming languageADA programming language
ADA programming languageAisha Kalsoom
 
Typed Drupal - A great combination of Drupal 8 and PHP 7
Typed Drupal - A great combination of Drupal 8 and PHP 7Typed Drupal - A great combination of Drupal 8 and PHP 7
Typed Drupal - A great combination of Drupal 8 and PHP 7Aditya Ghan
 
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages Charitha Gamage
 
Standards For Java Coding
Standards For Java CodingStandards For Java Coding
Standards For Java CodingRahul Bhutkar
 
Python and Zope: An introduction (May 2004)
Python and Zope: An introduction (May 2004)Python and Zope: An introduction (May 2004)
Python and Zope: An introduction (May 2004)Kiran Jonnalagadda
 

Was ist angesagt? (15)

Lifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeLifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During Lunchtime
 
Chapter1pp
Chapter1ppChapter1pp
Chapter1pp
 
Clean code
Clean codeClean code
Clean code
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Javascript
JavascriptJavascript
Javascript
 
Dart ppt
Dart pptDart ppt
Dart ppt
 
Groovy Programming Language
Groovy Programming LanguageGroovy Programming Language
Groovy Programming Language
 
ADA programming language
ADA programming languageADA programming language
ADA programming language
 
Typed Drupal - A great combination of Drupal 8 and PHP 7
Typed Drupal - A great combination of Drupal 8 and PHP 7Typed Drupal - A great combination of Drupal 8 and PHP 7
Typed Drupal - A great combination of Drupal 8 and PHP 7
 
Scala’s implicits
Scala’s implicitsScala’s implicits
Scala’s implicits
 
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
 
Standards For Java Coding
Standards For Java CodingStandards For Java Coding
Standards For Java Coding
 
Dart programming language
Dart programming languageDart programming language
Dart programming language
 
Python and Zope: An introduction (May 2004)
Python and Zope: An introduction (May 2004)Python and Zope: An introduction (May 2004)
Python and Zope: An introduction (May 2004)
 

Ähnlich wie PSR: Standards in PHP by Alex Simanovich

Submit PHP: Standards in PHP world. Михайло Морозов
Submit PHP: Standards in PHP world. Михайло МорозовSubmit PHP: Standards in PHP world. Михайло Морозов
Submit PHP: Standards in PHP world. Михайло МорозовBinary Studio
 
Standards: Don't pee in the pool
Standards: Don't pee in the poolStandards: Don't pee in the pool
Standards: Don't pee in the poolDavid Yell
 
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Antonio Peric-Mazar
 
A quick start on Zend Framework 2
A quick start on Zend Framework 2A quick start on Zend Framework 2
A quick start on Zend Framework 2Enrico Zimuel
 
The beautyandthebeast phpbat2010
The beautyandthebeast phpbat2010The beautyandthebeast phpbat2010
The beautyandthebeast phpbat2010Bastian Feder
 
Code quality tools for dev
Code quality tools for devCode quality tools for dev
Code quality tools for devDeepu S Nath
 
PHPCR - Standard Content Repository for PHP
PHPCR - Standard Content Repository for PHPPHPCR - Standard Content Repository for PHP
PHPCR - Standard Content Repository for PHPHenri Bergius
 
The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09Bastian Feder
 
The Beauty and the Beast
The Beauty and the BeastThe Beauty and the Beast
The Beauty and the BeastBastian Feder
 
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?Wong Hoi Sing Edison
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Tips
TipsTips
Tipsmclee
 
Php Best Practices
Php Best PracticesPhp Best Practices
Php Best PracticesAnsar Ahmed
 
Php Best Practices
Php Best PracticesPhp Best Practices
Php Best PracticesAnsar Ahmed
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Bastian Feder
 

Ähnlich wie PSR: Standards in PHP by Alex Simanovich (20)

Submit PHP: Standards in PHP world. Михайло Морозов
Submit PHP: Standards in PHP world. Михайло МорозовSubmit PHP: Standards in PHP world. Михайло Морозов
Submit PHP: Standards in PHP world. Михайло Морозов
 
PHP Development Tools
PHP  Development ToolsPHP  Development Tools
PHP Development Tools
 
Standards: Don't pee in the pool
Standards: Don't pee in the poolStandards: Don't pee in the pool
Standards: Don't pee in the pool
 
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
 
A quick start on Zend Framework 2
A quick start on Zend Framework 2A quick start on Zend Framework 2
A quick start on Zend Framework 2
 
The beautyandthebeast phpbat2010
The beautyandthebeast phpbat2010The beautyandthebeast phpbat2010
The beautyandthebeast phpbat2010
 
Code quality tools for dev
Code quality tools for devCode quality tools for dev
Code quality tools for dev
 
PHPCR - Standard Content Repository for PHP
PHPCR - Standard Content Repository for PHPPHPCR - Standard Content Repository for PHP
PHPCR - Standard Content Repository for PHP
 
The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09
 
The Beauty and the Beast
The Beauty and the BeastThe Beauty and the Beast
The Beauty and the Beast
 
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
 
Rebuilding our Foundation
Rebuilding our FoundationRebuilding our Foundation
Rebuilding our Foundation
 
Why Drupal is Rockstar?
Why Drupal is Rockstar?Why Drupal is Rockstar?
Why Drupal is Rockstar?
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Tips
TipsTips
Tips
 
Php Best Practices
Php Best PracticesPhp Best Practices
Php Best Practices
 
Php Best Practices
Php Best PracticesPhp Best Practices
Php Best Practices
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009
 
ZF2 Presentation @PHP Tour 2011 in Lille
ZF2 Presentation @PHP Tour 2011 in LilleZF2 Presentation @PHP Tour 2011 in Lille
ZF2 Presentation @PHP Tour 2011 in Lille
 

Kürzlich hochgeladen

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 

Kürzlich hochgeladen (20)

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 

PSR: Standards in PHP by Alex Simanovich

  • 3. PHP Standards for Writing Code PEAR Zend Framework Drupal Mine standards … etc
  • 4. Framework Interoperability Group - FIG ◦ Michael Dowling (AWS SDK for PHP) ◦ Larry Masters (CakePHP) ◦ Guilherme Blanco (Doctrine) ◦ Larry Garfield (Drupal) ◦ Filipe Guerra (SugarCRM) ◦ Bernhard Schussek (Symfony2) ◦ Alexander Makarov (Yii framework) ◦ Pádraic Brady (Zend Framework 2)
  • 5. FIG’s Goal The goal of the FIG is to create a dialogue between project representatives, with the aim of finding ways to work together (interoperability)
  • 7. Tools require() in PHP 4 __autoload() in PHP 5 spl_autoload() and spl_autoload_register() in PHP 5.1.2
  • 8. Requirements ◦ A fully-qualified namespace and class must have the following structure <Vendor Name>(<Namespace>)*<Class Name> ◦ Each namespace must have a top-level namespace ("Vendor Name"). ◦ Each namespace can have as many sub-namespaces as it wishes. ◦ Each namespace separator is converted to a DIRECTORY_SEPARATOR when loading from the file system. ◦ Each _ character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. The _ character has no special meaning in the namespace. ◦ The fully-qualified namespace and class is suffixed with .php when loading from the file system. ◦ Alphabetic characters in vendor names, namespaces, and class names may be of any combination of lower case and upper case.
  • 9. Example ◦ DoctrineCommonIsolatedClassLoader => /path/to/project/lib/vendor/Doctrine/Common/IsolatedClassLoader.php ◦ SymfonyCoreRequest => /path/to/project/lib/vendor/Symfony/Core/Request.php ◦ ZendAcl => /path/to/project/lib/vendor/Zend/Acl.php ◦ ZendMailMessage => /path/to/project/lib/vendor/Zend/Mail/Message.php ◦ namespacepackageClass_Name => /path/to/project/lib/vendor/namespace/package/Class/Name.php ◦ namespacepackage_nameClass_Name => /path/to/project/lib/vendor/namespace/package_name/Class/Name.php
  • 10. PSR-0: not for PHP core
  • 12. Basic Coding Standard ◦ Only use the <?php and <?= tags. ◦ Only use UTF-8 without BOM for PHP code. ◦ Separate side-effects (generate output, access a database etc.) and declarations. ◦ Enforce PSR-0. ◦ Class names must be defined in StudlyCaps. ◦ Class constants must be defined in upper case with underscore separators. ◦ Method names must be defined in camelCase.
  • 16. Logger Interface ◦ The LoggerInterface exposes eight methods to write logs to the eight RFC 5424 levels (debug, info, notice, warning, error, critical, alert, emergency) ◦ A ninth method, log, accepts a log level as first argument. Calling this method with one of the log level constants MUST have the same result as calling the level-specific method. Calling this method with a level not defined by this specification MUST throw a PsrLogInvalidArgumentException if the implementation does not know about the level. Users SHOULD NOT use a custom level without knowing for sure the current implementation supports it. https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
  • 21. Often hear Too far Subjective Too specific Not flexible
  • 22. Become PHP-FIG community member https://groups.google.com/forum/#!forum/php-fig
  • 23. Thanks • Email: ax.simanovich@gmail.com • Skype: aliaksandr.simanovich • Twitter: @simanjan • Blog: simanovich.info

Hinweis der Redaktion

  1. http://net.tutsplus.com/tutorials/php/psr-huh/ https://groups.google.com/forum/#!forum/php-fig https://github.com/php-fig/fig-standards http://www.php-fig.org/ http://petermoulding.com/php/psr http://hybridlogic.co.uk/2012/04/psr-0-great-idea-bastardised-execution/ http://www.reddit.com/r/PHP/comments/1kvr1f/the_new_autoloading_standard_psr4_passes_entrance/ http://blog.ircmaxell.com/2011/11/on-psr-0-being-included-in-phps-core.html https://wiki.php.net/rfc/splclassloader/vote https://drupal.org/project/psr0 http://paul-m-jones.com/archives/2420
  2. PHP Standards Group Not only frameworks
  3. No matter how good the autoloading functionality is, it does not define how to implement it with existing codebases. For example, library X might approach the directory and classname structure differently than library Y, but you might want to use both! Writing a proper autoloader that knows where to look for all possible fully-qualified names, as well as test all file extensions (.class.php, inc.php, .php etc) will quickly become a mess.
  4. https://wiki.php.net/rfc/splclassloader https://wiki.php.net/rfc/splclassloader/vote
  5. https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md http://www.sitepoint.com/battle-autoloaders-psr-0-vs-psr-4/