SlideShare a Scribd company logo
PHP Standards
Recommendations
(PSR)
Akshay Khale

(Sr. Software Engineer)
– Martin Fowler
“Any fool can write code that a computer can
understand. Good programmers write code that
humans can understand.”
PSR-1: Basic Coding
Standards.
• MUST use only <?php and <?= tags.

• MUST use only UTF-8 Encoding.

• SHOULD either declare symbols or cause side-effects.

• Class names MUST be declared in CamelCase or
StudlyCaps.

• constants MUST be declared in all UPPER_SNAKE_CASE.

• Method names MUST be declared in camelCase.
Quiz Time: What is wrong with
following code snippets?
PSR-2: Coding Style Guide
• 4 Space indenting (No Tabs).

• Soft Line limit 120 Characters.

• Blank space after namespace declaration before use.

• Closing Brace “}” always on a separate line.

• Opening Brace “{” Same line (with a space before) for control statements
and next line for Classes and functions.

• Space before open parentheses “(” for control statements and not for
functions.

• Visibility mode is must for all properties and methods. abstract and final
before visibility and static after the visibility.
Quiz Time: What is wrong with
following code snippets?
PSR-3: Logger Interface
• Only allowed Log levels: debug, info, notice, warning, error,
critical, alert, emergency.

• MUST implement PsrLogLoggerInterface.

• MUST throw PsrLogInvalidArgumentException exception
on invalid log level.

• public function log($level, $message, array $context =
array());
• One can consider extending PsrLogAbstractLogger class
which implements LoggerInterface.
Sample Logger Class:
https://github.com/akshaykhale1992/luxio-logger
PSR-4: Autoloader
• Namespace: <vendor_namespace>/
<package_namespace>[/<subnamespace>/]/
<class_name>.

• Folder structure should also follow the namespace
pattern.
PSR-6: Caching Interface
• MUST implement PsrCacheCacheItemPoolInterface and
PsrCacheCacheItemInterface.

• Concepts: Pool, Items, Key, Data, TTL, Hit, Miss.

• Should not throw any Exception.
PSR-7: HTTP message
interfaces
• Request Structure

• Response Structure

• Interfaces: PsrHttpMessageRequestInterface and
PsrHttpMessageResponseInterface.
PSR-11: Container interface
• MUST implement PsrContainerContainerInterface.

• MUST throw PsrContainerNotFoundExceptionInterface
exception if object not found.

• Directly thrown exceptions must implement
PsrContainerContainerExceptionInterface interface.
Standards that most of the
developers follow.
• If a file defines a Class then it should not have any other declarations though PSR
allows.

• Files with functions should have only function definitions.

• Files with class / functions definitions should not have a closing PHP Tag (?>) and
should have an empty line before EOF.

• Helper files must have function_exists check.

• Code MUST be correctly formatted based on the PSR rules. (editor plugins can be used
for the same).

• Arrays properties should be on separate lines.

• All declarations MUST have dock-blocks.

• Branch names MUST follow bitbucket Branching Model.
Cont.
• Use static instead of self for calling static class members.

• Use die instead of exit.

• Make use of destructors for unsetting objects and/or closing opened files.

• There should not be any commented code or commented die / dd statements.

• SHOULD avoid else block in case of if statements.

• Recommended to make use of exceptions in-case of invalid details which should be
handles at calling end.

• Try to use User defined constants instead of System constants. A constants class should
be created for defining all the constants that are being used in the project. E.g. instead of
using “/” for directory paths use DIRECTORY_SEPARATOR or instead of using supplier_id
== 7 check use supplier_id == Constants::DELHIVERY_SUPPLIER_ID.

• PHP Unit Test cases are compulsory.
Samples:
Thank you!!!

More Related Content

What's hot

STA.pdf
STA.pdfSTA.pdf
6. Design Planning.pdf
6. Design Planning.pdf6. Design Planning.pdf
6. Design Planning.pdf
Ahmed Abdelazeem
 
SystemVerilog based OVM and UVM Verification Methodologies
SystemVerilog based OVM and UVM Verification MethodologiesSystemVerilog based OVM and UVM Verification Methodologies
SystemVerilog based OVM and UVM Verification Methodologies
Ramdas Mozhikunnath
 
AMBA3.0 james_20110801
AMBA3.0 james_20110801AMBA3.0 james_20110801
AMBA3.0 james_20110801
James Chang
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
Weber Tsai
 
AXI Protocol.pptx
AXI Protocol.pptxAXI Protocol.pptx
AXI Protocol.pptx
Yazan Yousef
 
Pci express modi
Pci express modiPci express modi
Pci express modi
proma_goswami
 
Cpu Cache and Memory Ordering——并发程序设计入门
Cpu Cache and Memory Ordering——并发程序设计入门Cpu Cache and Memory Ordering——并发程序设计入门
Cpu Cache and Memory Ordering——并发程序设计入门
frogd
 
Memory ECC - The Comprehensive of SEC-DED.
Memory ECC - The Comprehensive of SEC-DED. Memory ECC - The Comprehensive of SEC-DED.
Memory ECC - The Comprehensive of SEC-DED.
Sk Cheah
 
Verification of uart ip core using uvm
Verification of uart ip core using uvmVerification of uart ip core using uvm
Verification of uart ip core using uvm
eSAT Publishing House
 
Axi
AxiAxi
Complete ASIC design flow - VLSI UNIVERSE
Complete ASIC design flow - VLSI UNIVERSEComplete ASIC design flow - VLSI UNIVERSE
Complete ASIC design flow - VLSI UNIVERSE
VLSIUNIVERSE
 
AMBA Ahb 2.0
AMBA Ahb 2.0AMBA Ahb 2.0
AMBA Ahb 2.0
Akhil Srivastava
 
Challenges in Using UVM at SoC Level
Challenges in Using UVM at SoC LevelChallenges in Using UVM at SoC Level
Challenges in Using UVM at SoC Level
DVClub
 
System verilog control flow
System verilog control flowSystem verilog control flow
System verilog control flow
Pushpa Yakkala
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features Summary
Amal Khailtash
 
System Verilog 2009 & 2012 enhancements
System Verilog 2009 & 2012 enhancementsSystem Verilog 2009 & 2012 enhancements
System Verilog 2009 & 2012 enhancements
Subash John
 
Axi protocol
Axi protocolAxi protocol
Axi protocol
Azad Mishra
 
AMBA AHB 5
AMBA AHB 5AMBA AHB 5
AMBA AHB 5
SUNODH GARLAPATI
 
4. Formal Equivalence Checking (Formality).pptx
4. Formal Equivalence Checking (Formality).pptx4. Formal Equivalence Checking (Formality).pptx
4. Formal Equivalence Checking (Formality).pptx
Ahmed Abdelazeem
 

What's hot (20)

STA.pdf
STA.pdfSTA.pdf
STA.pdf
 
6. Design Planning.pdf
6. Design Planning.pdf6. Design Planning.pdf
6. Design Planning.pdf
 
SystemVerilog based OVM and UVM Verification Methodologies
SystemVerilog based OVM and UVM Verification MethodologiesSystemVerilog based OVM and UVM Verification Methodologies
SystemVerilog based OVM and UVM Verification Methodologies
 
AMBA3.0 james_20110801
AMBA3.0 james_20110801AMBA3.0 james_20110801
AMBA3.0 james_20110801
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
 
AXI Protocol.pptx
AXI Protocol.pptxAXI Protocol.pptx
AXI Protocol.pptx
 
Pci express modi
Pci express modiPci express modi
Pci express modi
 
Cpu Cache and Memory Ordering——并发程序设计入门
Cpu Cache and Memory Ordering——并发程序设计入门Cpu Cache and Memory Ordering——并发程序设计入门
Cpu Cache and Memory Ordering——并发程序设计入门
 
Memory ECC - The Comprehensive of SEC-DED.
Memory ECC - The Comprehensive of SEC-DED. Memory ECC - The Comprehensive of SEC-DED.
Memory ECC - The Comprehensive of SEC-DED.
 
Verification of uart ip core using uvm
Verification of uart ip core using uvmVerification of uart ip core using uvm
Verification of uart ip core using uvm
 
Axi
AxiAxi
Axi
 
Complete ASIC design flow - VLSI UNIVERSE
Complete ASIC design flow - VLSI UNIVERSEComplete ASIC design flow - VLSI UNIVERSE
Complete ASIC design flow - VLSI UNIVERSE
 
AMBA Ahb 2.0
AMBA Ahb 2.0AMBA Ahb 2.0
AMBA Ahb 2.0
 
Challenges in Using UVM at SoC Level
Challenges in Using UVM at SoC LevelChallenges in Using UVM at SoC Level
Challenges in Using UVM at SoC Level
 
System verilog control flow
System verilog control flowSystem verilog control flow
System verilog control flow
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features Summary
 
System Verilog 2009 & 2012 enhancements
System Verilog 2009 & 2012 enhancementsSystem Verilog 2009 & 2012 enhancements
System Verilog 2009 & 2012 enhancements
 
Axi protocol
Axi protocolAxi protocol
Axi protocol
 
AMBA AHB 5
AMBA AHB 5AMBA AHB 5
AMBA AHB 5
 
4. Formal Equivalence Checking (Formality).pptx
4. Formal Equivalence Checking (Formality).pptx4. Formal Equivalence Checking (Formality).pptx
4. Formal Equivalence Checking (Formality).pptx
 

Similar to PHP Standards Recommendations - PHP-FIG

Php psr standard 2014 01-22
Php psr standard 2014 01-22Php psr standard 2014 01-22
Php psr standard 2014 01-22
Võ Duy Tuấn
 
Shellcode mastering
Shellcode masteringShellcode mastering
Shellcode mastering
Positive Hack Days
 
Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.
Positive Hack Days
 
Psr 2 coding style guide - Tidepool Labs
Psr 2   coding style guide - Tidepool LabsPsr 2   coding style guide - Tidepool Labs
Psr 2 coding style guide - Tidepool Labs
Harutyun Abgaryan
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
Ahmed Raza
 
Psr - php standards recommendations
Psr - php standards recommendationsPsr - php standards recommendations
Psr - php standards recommendations
Hà Anh Sơn
 
Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.
Leekas Shep
 
An intro to php standards recommendation (psr)
An intro to php standards recommendation (psr)An intro to php standards recommendation (psr)
An intro to php standards recommendation (psr)
valuebound
 
Scala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and qualityScala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and quality
Jaime Jorge
 
Programming best practices (PHP)
Programming best practices (PHP)Programming best practices (PHP)
Programming best practices (PHP)
Clique Studios
 
1. Coding Conventions [Part 1]
1. Coding Conventions [Part 1]1. Coding Conventions [Part 1]
1. Coding Conventions [Part 1]
Hardik Patel
 
Presentation
PresentationPresentation
Presentation
bugway
 
Java platform
Java platformJava platform
Java platform
Visithan
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
AAFREEN SHAIKH
 
Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...
Alexey Diyan
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
Tobias Coetzee
 
PPT 19.pptx
PPT 19.pptxPPT 19.pptx
PPT 19.pptx
DrRavneetSingh
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
Amirul Shafeeq
 
Server Scripting Language -PHP
Server Scripting Language -PHPServer Scripting Language -PHP
Server Scripting Language -PHP
Deo Shao
 
A Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and UnderstandingA Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and Understanding
mametter
 

Similar to PHP Standards Recommendations - PHP-FIG (20)

Php psr standard 2014 01-22
Php psr standard 2014 01-22Php psr standard 2014 01-22
Php psr standard 2014 01-22
 
Shellcode mastering
Shellcode masteringShellcode mastering
Shellcode mastering
 
Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.
 
Psr 2 coding style guide - Tidepool Labs
Psr 2   coding style guide - Tidepool LabsPsr 2   coding style guide - Tidepool Labs
Psr 2 coding style guide - Tidepool Labs
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Psr - php standards recommendations
Psr - php standards recommendationsPsr - php standards recommendations
Psr - php standards recommendations
 
Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.
 
An intro to php standards recommendation (psr)
An intro to php standards recommendation (psr)An intro to php standards recommendation (psr)
An intro to php standards recommendation (psr)
 
Scala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and qualityScala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and quality
 
Programming best practices (PHP)
Programming best practices (PHP)Programming best practices (PHP)
Programming best practices (PHP)
 
1. Coding Conventions [Part 1]
1. Coding Conventions [Part 1]1. Coding Conventions [Part 1]
1. Coding Conventions [Part 1]
 
Presentation
PresentationPresentation
Presentation
 
Java platform
Java platformJava platform
Java platform
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
 
Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
PPT 19.pptx
PPT 19.pptxPPT 19.pptx
PPT 19.pptx
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
 
Server Scripting Language -PHP
Server Scripting Language -PHPServer Scripting Language -PHP
Server Scripting Language -PHP
 
A Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and UnderstandingA Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and Understanding
 

Recently uploaded

Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
MiscAnnoy1
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Hematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood CountHematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood Count
shahdabdulbaset
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 

Recently uploaded (20)

Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Hematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood CountHematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood Count
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 

PHP Standards Recommendations - PHP-FIG

  • 2. – Martin Fowler “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”
  • 3. PSR-1: Basic Coding Standards. • MUST use only <?php and <?= tags. • MUST use only UTF-8 Encoding. • SHOULD either declare symbols or cause side-effects. • Class names MUST be declared in CamelCase or StudlyCaps. • constants MUST be declared in all UPPER_SNAKE_CASE. • Method names MUST be declared in camelCase.
  • 4. Quiz Time: What is wrong with following code snippets?
  • 5. PSR-2: Coding Style Guide • 4 Space indenting (No Tabs). • Soft Line limit 120 Characters. • Blank space after namespace declaration before use. • Closing Brace “}” always on a separate line. • Opening Brace “{” Same line (with a space before) for control statements and next line for Classes and functions. • Space before open parentheses “(” for control statements and not for functions. • Visibility mode is must for all properties and methods. abstract and final before visibility and static after the visibility.
  • 6. Quiz Time: What is wrong with following code snippets?
  • 7. PSR-3: Logger Interface • Only allowed Log levels: debug, info, notice, warning, error, critical, alert, emergency. • MUST implement PsrLogLoggerInterface. • MUST throw PsrLogInvalidArgumentException exception on invalid log level. • public function log($level, $message, array $context = array()); • One can consider extending PsrLogAbstractLogger class which implements LoggerInterface.
  • 9. PSR-4: Autoloader • Namespace: <vendor_namespace>/ <package_namespace>[/<subnamespace>/]/ <class_name>. • Folder structure should also follow the namespace pattern.
  • 10. PSR-6: Caching Interface • MUST implement PsrCacheCacheItemPoolInterface and PsrCacheCacheItemInterface. • Concepts: Pool, Items, Key, Data, TTL, Hit, Miss. • Should not throw any Exception.
  • 11. PSR-7: HTTP message interfaces • Request Structure • Response Structure • Interfaces: PsrHttpMessageRequestInterface and PsrHttpMessageResponseInterface.
  • 12. PSR-11: Container interface • MUST implement PsrContainerContainerInterface. • MUST throw PsrContainerNotFoundExceptionInterface exception if object not found. • Directly thrown exceptions must implement PsrContainerContainerExceptionInterface interface.
  • 13. Standards that most of the developers follow. • If a file defines a Class then it should not have any other declarations though PSR allows. • Files with functions should have only function definitions. • Files with class / functions definitions should not have a closing PHP Tag (?>) and should have an empty line before EOF. • Helper files must have function_exists check. • Code MUST be correctly formatted based on the PSR rules. (editor plugins can be used for the same). • Arrays properties should be on separate lines. • All declarations MUST have dock-blocks. • Branch names MUST follow bitbucket Branching Model.
  • 14. Cont. • Use static instead of self for calling static class members. • Use die instead of exit. • Make use of destructors for unsetting objects and/or closing opened files. • There should not be any commented code or commented die / dd statements. • SHOULD avoid else block in case of if statements. • Recommended to make use of exceptions in-case of invalid details which should be handles at calling end. • Try to use User defined constants instead of System constants. A constants class should be created for defining all the constants that are being used in the project. E.g. instead of using “/” for directory paths use DIRECTORY_SEPARATOR or instead of using supplier_id == 7 check use supplier_id == Constants::DELHIVERY_SUPPLIER_ID. • PHP Unit Test cases are compulsory.