Open In App

PHP | Coding Standards

PHP follows few rules and maintains its style of coding. As there are many developers all over the world, if each of them follows different coding styles and standards this will raise great confusion and difficulty for a developer to understand another developer’s code. It will be very hard to manage and store the code for future reference. 

The coding standards come into play for all the reasons. 



Reasons for maintaining coding standards:

Below mentioned are few guidelines that one must follow in order to maintain the standard of PHP coding. 



  Full tags :

<?PHP
  PHP code
?>                

   Short tags:

<?
  PHP code
?>

   

Example: 




<?php
 
$n = 5;
if ($n > 0){
    echo "Positive";
}
elseif ($n < 0){
    echo "Negative";
}
else{
    echo "Zero";
}
 
?>

Output: 

Positive

 Example: 
 




<?php
 
echo testFunc(5, 6);
 
function testFunc($num1, $num2) {
   $val = $num1 + $num2;
   return $val;
}
 
?>

Output: 
 

11

Note: The above rules are provided just to make the code easily understandable and to manage the code easily. There will not be any specific error in case of violation of the rules mentioned above. But it is highly recommended following the above convention to improve the overall quality of code from a developer’s perspective.
 


Article Tags :