SlideShare a Scribd company logo
1 of 16
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

What's hot

Presentation on Template Method Design Pattern
Presentation on Template Method Design PatternPresentation on Template Method Design Pattern
Presentation on Template Method Design PatternAsif Tayef
 
Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptBinu Paul
 
How to test models using php unit testing framework?
How to test models using php unit testing framework?How to test models using php unit testing framework?
How to test models using php unit testing framework?satejsahu
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsqlArun Sial
 
Template method pattern example
Template method pattern exampleTemplate method pattern example
Template method pattern exampleGuo Albert
 
Template Method Pattern
Template Method PatternTemplate Method Pattern
Template Method Patternmonisiqbal
 
Code refactoring workshop (in Javascript)
Code refactoring workshop (in Javascript)Code refactoring workshop (in Javascript)
Code refactoring workshop (in Javascript)Ilias Bartolini
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6helpido9
 
Magento Integration Tests
Magento Integration TestsMagento Integration Tests
Magento Integration TestsX.commerce
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails AppsRabble .
 

What's hot (14)

Presentation on Template Method Design Pattern
Presentation on Template Method Design PatternPresentation on Template Method Design Pattern
Presentation on Template Method Design Pattern
 
Testing 101
Testing 101Testing 101
Testing 101
 
Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to Javascript
 
How to test models using php unit testing framework?
How to test models using php unit testing framework?How to test models using php unit testing framework?
How to test models using php unit testing framework?
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsql
 
Template method pattern example
Template method pattern exampleTemplate method pattern example
Template method pattern example
 
Template Method Pattern
Template Method PatternTemplate Method Pattern
Template Method Pattern
 
Code refactoring workshop (in Javascript)
Code refactoring workshop (in Javascript)Code refactoring workshop (in Javascript)
Code refactoring workshop (in Javascript)
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Magento Integration Tests
Magento Integration TestsMagento Integration Tests
Magento Integration Tests
 
Php 7 crash course
Php 7 crash coursePhp 7 crash course
Php 7 crash course
 
Plsql
PlsqlPlsql
Plsql
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
 

Viewers also liked

Data Cleaning Checklist
Data Cleaning ChecklistData Cleaning Checklist
Data Cleaning ChecklistDrive Research
 
Code Review
Code ReviewCode Review
Code ReviewTu Hoang
 
PHP Static Code Review
PHP Static Code ReviewPHP Static Code Review
PHP Static Code ReviewDamien Seguy
 
Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)Damien Seguy
 
The pragmatic programmer
The pragmatic programmerThe pragmatic programmer
The pragmatic programmerJoel Corrêa
 
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
 
Code review process checklist by VINTAGE
Code review process checklist by VINTAGECode review process checklist by VINTAGE
Code review process checklist by VINTAGEDenis Kurylenko
 
Code Review Checklist
Code Review ChecklistCode Review Checklist
Code Review ChecklistNitin Bhide
 
PHP security audits
PHP security auditsPHP security audits
PHP security auditsDamien Seguy
 

Viewers also liked (13)

Data Cleaning Checklist
Data Cleaning ChecklistData Cleaning Checklist
Data Cleaning Checklist
 
Code Review
Code ReviewCode Review
Code Review
 
PHP Static Code Review
PHP Static Code ReviewPHP Static Code Review
PHP Static Code Review
 
MCU compare
MCU compareMCU compare
MCU compare
 
Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)
 
Manual Code Review
Manual Code ReviewManual Code Review
Manual Code Review
 
Code review
Code reviewCode review
Code review
 
The pragmatic programmer
The pragmatic programmerThe pragmatic programmer
The pragmatic programmer
 
Submit PHP: Standards in PHP world. Михайло Морозов
Submit PHP: Standards in PHP world. Михайло МорозовSubmit PHP: Standards in PHP world. Михайло Морозов
Submit PHP: Standards in PHP world. Михайло Морозов
 
Code review process checklist by VINTAGE
Code review process checklist by VINTAGECode review process checklist by VINTAGE
Code review process checklist by VINTAGE
 
Code Review Checklist
Code Review ChecklistCode Review Checklist
Code Review Checklist
 
PHP security audits
PHP security auditsPHP security audits
PHP security audits
 
Code metrics in PHP
Code metrics in PHPCode metrics in PHP
Code metrics in PHP
 

Similar to PHP coding tips and review guides

PHP 7 Crash Course
PHP 7 Crash CoursePHP 7 Crash Course
PHP 7 Crash CourseColin O'Dell
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Mir Nazim
 
Workshop: Refactoring Legacy PHP: The Complete Guide
Workshop: Refactoring Legacy PHP: The Complete Guide Workshop: Refactoring Legacy PHP: The Complete Guide
Workshop: Refactoring Legacy PHP: The Complete Guide Junade Ali
 
Alive and Well with Java 8
Alive and Well with Java 8Alive and Well with Java 8
Alive and Well with Java 8Adam Pelsoczi
 
Standard Coding, OOP Techniques and Code Reuse
Standard Coding, OOP Techniques and Code ReuseStandard Coding, OOP Techniques and Code Reuse
Standard Coding, OOP Techniques and Code ReuseRayhan Chowdhury
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshopjulien pauli
 
Drupal debugging tips
Drupal debugging tipsDrupal debugging tips
Drupal debugging tipsAdolfo Nasol
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015Colin O'Dell
 
Php 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparisonPhp 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparisonTu Pham
 
PHP 7X New Features
PHP 7X New FeaturesPHP 7X New Features
PHP 7X New FeaturesThanh Tai
 
The PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
The PHP mysqlnd plugin talk - plugins an alternative to MySQL ProxyThe PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
The PHP mysqlnd plugin talk - plugins an alternative to MySQL ProxyUlf Wendel
 

Similar to PHP coding tips and review guides (20)

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

Recently uploaded

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 

Recently uploaded (20)

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 

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