SlideShare a Scribd company logo
PHP Coding Standars. 
Code Review Tips
1. Error Suppression 
- @ operator not allowed 
- error_reporting(E_STRICT); should be defined 
in code for dev & qa platforms (not prod!)
2. global keyword 
PHP allows to define vars as global. If it's done 
in function it breaks function scope. Globals 
are not allowed.
3. Depricated features 
Don't use depricated features in your code 
PHP 5.3 - http://php.net/manual/en/migration53.deprecated.php 
PHP 5.4 - http://php.net/manual/en/migration54.deprecated.php 
PHP 5.5 - http://php.net/manual/en/migration55.deprecated.php 
PHP 5.6 - http://php.net/manual/en/migration56.deprecated.php
4. include_once() & require_once() 
- Use these function when they are extremelly required 
- Not allowed to use them inside of class methods 
- Use autoloading instead
5. Redundant Code 
If($var == “true”){ 
return true; 
} else{ 
return false; 
} <==== NOT OK. Use following instead 
return ($var == “true”) ? true: false; <== BUT 
don't make it nested!!
6. Redundant Booleans 
Actually this looks bad also 
return ($isBad) ? true : false; 
it's the same as 
return $isBad;
7. Accidental Assignment 
if($a = ”some value”) <== this will always give 
“true” to avoid this you can use 
if(“some value” == $a) – so if “=” is missed an 
error will be produced
8. Use type hinting 
If your method takes an object as an argument 
then type of the object should be defined: 
public function doSomething($object) <== BAD 
public function doSmth(Obj_Type $obj) <== 
good
9. Use === instead of ==. 
- You can rely on variable type 
- This will improve performance 
- This also relates to other comparison operators
10. Nested code blocks 
- Only 2 nested code blocks allowed 
if($a){ 
$x = 5; 
if($b){ 
$x = 8; 
if($c){ 
$s = 9; 
} 
} 
} <== this is bad code. Declare new function to 
resolve it
11. Quering DB in loops 
- Quering DB in loops is not allowed 
- Use IN (X, Y, Z) instead
12. Copy-paste code 
- IT'S TOTALLY FORBIDDEN
13. Comments 
- Comments should be added to each class 
- Comments should be added to each method 
and field 
- If method does something complicated 
comments may exist in method body
14. Single function is doing only one 
thing 
- If you have function getUsers() it should just 
return users but not delete them or return 
some other things
15. General code recommendations 
- A method should not be larger than 40 lines of 
code so function is viewable with out scrolling. 
- Always initialize the variable before using it. 
- No public class attributes. 
- Don't query DB from view layer 
- Always try using single quote ( ‘ ) when working 
with the php string

More Related Content

PPT
Zend Framework 2 - PHPUnit
PDF
Railway Oriented Programming in Elixir
PPT
Preprocessor
PPTX
Design patterns: template method
PPT
Template Method Design Pattern
PPTX
Apply Template Method Pattern in Report Implementation
ODP
Oracle Objects And Transactions
PPT
Basics of java 1
Zend Framework 2 - PHPUnit
Railway Oriented Programming in Elixir
Preprocessor
Design patterns: template method
Template Method Design Pattern
Apply Template Method Pattern in Report Implementation
Oracle Objects And Transactions
Basics of java 1

What's hot (14)

PPTX
Presentation on Template Method Design Pattern
PPTX
Testing 101
PPTX
Cordova training : Day 3 - Introduction to Javascript
PPT
How to test models using php unit testing framework?
PDF
Exception handling in plsql
PPT
Template method pattern example
PPT
Template Method Pattern
PDF
Code refactoring workshop (in Javascript)
DOCX
Cis 355 i lab 1 of 6
PPTX
Magento Integration Tests
PDF
Php 7 crash course
PPT
PPTX
Laravel Unit Testing
PDF
Testing Legacy Rails Apps
Presentation on Template Method Design Pattern
Testing 101
Cordova training : Day 3 - Introduction to Javascript
How to test models using php unit testing framework?
Exception handling in plsql
Template method pattern example
Template Method Pattern
Code refactoring workshop (in Javascript)
Cis 355 i lab 1 of 6
Magento Integration Tests
Php 7 crash course
Laravel Unit Testing
Testing Legacy Rails Apps
Ad

Viewers also liked (13)

PPTX
Data Cleaning Checklist
PDF
Code Review
PDF
PHP Static Code Review
PPTX
MCU compare
KEY
Php Code Audits (PHP UK 2010)
PDF
PPTX
Code review
PDF
The pragmatic programmer
PDF
Submit PHP: Standards in PHP world. Михайло Морозов
PPTX
Code review process checklist by VINTAGE
PPTX
Code Review Checklist
KEY
PHP security audits
PDF
Code metrics in PHP
Data Cleaning Checklist
Code Review
PHP Static Code Review
MCU compare
Php Code Audits (PHP UK 2010)
Code review
The pragmatic programmer
Submit PHP: Standards in PHP world. Михайло Морозов
Code review process checklist by VINTAGE
Code Review Checklist
PHP security audits
Code metrics in PHP
Ad

Similar to PHP coding tips and review guides (20)

PDF
Start using PHP 7
PPT
Core java
PPTX
PHP 7 Crash Course
PDF
Drupal 8 - Core and API Changes
ODP
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
PDF
Workshop: Refactoring Legacy PHP: The Complete Guide
PDF
Alive and Well with Java 8
PPTX
Software Development with PHP & Laravel
PDF
Standard Coding, OOP Techniques and Code Reuse
PPTX
Zf2 phpquebec
ODP
Drupal Best Practices
PDF
Php7 extensions workshop
ODP
Drupal development
PDF
Drupal debugging tips
PPTX
PHP 7 Crash Course - php[world] 2015
PDF
PHP Development Tools
PPTX
Php 5.6 vs Php 7 performance comparison
PDF
PHP 7X New Features
ODP
The PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
PPT
Php Ppt
Start using PHP 7
Core java
PHP 7 Crash Course
Drupal 8 - Core and API Changes
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Workshop: Refactoring Legacy PHP: The Complete Guide
Alive and Well with Java 8
Software Development with PHP & Laravel
Standard Coding, OOP Techniques and Code Reuse
Zf2 phpquebec
Drupal Best Practices
Php7 extensions workshop
Drupal development
Drupal debugging tips
PHP 7 Crash Course - php[world] 2015
PHP Development Tools
Php 5.6 vs Php 7 performance comparison
PHP 7X New Features
The PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
Php Ppt

Recently uploaded (20)

PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
DOCX
573137875-Attendance-Management-System-original
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
“Next-Gen AI: Trends Reshaping Our World”
PDF
ETO & MEO Certificate of Competency Questions and Answers
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
PDF
Queuing formulas to evaluate throughputs and servers
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
bas. eng. economics group 4 presentation 1.pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
573137875-Attendance-Management-System-original
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
“Next-Gen AI: Trends Reshaping Our World”
ETO & MEO Certificate of Competency Questions and Answers
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
Queuing formulas to evaluate throughputs and servers
OOP with Java - Java Introduction (Basics)
Operating System & Kernel Study Guide-1 - converted.pdf
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf

PHP coding tips and review guides

  • 1. PHP Coding Standars. Code Review Tips
  • 2. 1. Error Suppression - @ operator not allowed - error_reporting(E_STRICT); should be defined in code for dev & qa platforms (not prod!)
  • 3. 2. global keyword PHP allows to define vars as global. If it's done in function it breaks function scope. Globals are not allowed.
  • 4. 3. Depricated features Don't use depricated features in your code PHP 5.3 - http://php.net/manual/en/migration53.deprecated.php PHP 5.4 - http://php.net/manual/en/migration54.deprecated.php PHP 5.5 - http://php.net/manual/en/migration55.deprecated.php PHP 5.6 - http://php.net/manual/en/migration56.deprecated.php
  • 5. 4. include_once() & require_once() - Use these function when they are extremelly required - Not allowed to use them inside of class methods - Use autoloading instead
  • 6. 5. Redundant Code If($var == “true”){ return true; } else{ return false; } <==== NOT OK. Use following instead return ($var == “true”) ? true: false; <== BUT don't make it nested!!
  • 7. 6. Redundant Booleans Actually this looks bad also return ($isBad) ? true : false; it's the same as return $isBad;
  • 8. 7. Accidental Assignment if($a = ”some value”) <== this will always give “true” to avoid this you can use if(“some value” == $a) – so if “=” is missed an error will be produced
  • 9. 8. Use type hinting If your method takes an object as an argument then type of the object should be defined: public function doSomething($object) <== BAD public function doSmth(Obj_Type $obj) <== good
  • 10. 9. Use === instead of ==. - You can rely on variable type - This will improve performance - This also relates to other comparison operators
  • 11. 10. Nested code blocks - Only 2 nested code blocks allowed if($a){ $x = 5; if($b){ $x = 8; if($c){ $s = 9; } } } <== this is bad code. Declare new function to resolve it
  • 12. 11. Quering DB in loops - Quering DB in loops is not allowed - Use IN (X, Y, Z) instead
  • 13. 12. Copy-paste code - IT'S TOTALLY FORBIDDEN
  • 14. 13. Comments - Comments should be added to each class - Comments should be added to each method and field - If method does something complicated comments may exist in method body
  • 15. 14. Single function is doing only one thing - If you have function getUsers() it should just return users but not delete them or return some other things
  • 16. 15. General code recommendations - A method should not be larger than 40 lines of code so function is viewable with out scrolling. - Always initialize the variable before using it. - No public class attributes. - Don't query DB from view layer - Always try using single quote ( ‘ ) when working with the php string