If you want others to understand your code then you have to follow some standards of coding. Sometimes a lot of coding is needed which may require a number of programmers so as to complete a big project. In such a situation you can get a lot of help from coding standards. There is a possibility of your own coding to be very hard to understand by you if you do not follow these standards. As per your needs the standards can undergo slight changes at the time of development. It needs to be perfect to deal with a project having acceptable and consistent changes made by you. Now I am going to describe about 3 PHP coding standards that you will love and how to use them.

1. Coding standards of FuelPHP – A PHP based web framework that is open source is FuelPHP. As compared to the PSR, a mindset of another type will be found in its standards. Today you will see Symfony and several other frameworks but this framework is newer.

The Variables and Methods have various conventions of naming

If you are using variable names and methods then snake_case will work for you in FuelPHP. PSR-2 has mentioned in its methods and classes that prior to { a newline can be put by you. An underscore will be used to show the properties and methods of the protected and private names.

Class Session

{

protected $_data;

public static function get_flash ($name, $data)

{

/ /   . . .

}

private function _private_method ($argument_name)

{

/ /   . . .

}

}

snake_case is used for defining PHP’s standard functions

We can call it the old practice’s remainder to use underscore with those names of property and method that are protected or private. An underscore was used for properties and methods that are private so as to initiate the names. It is so because earlier it was not possible to define properties and methods that are private when there was no PHP4.

What will happen if in conditional statements before using curly braces we put a newline?

In conditional statements anything related to curly braces was not mentioned and in the definitions of method and class, prior to curly braces a new line needs to be put by you in PSR-2. In conditional statements, prior to curly braces a new line has to be put by you in FuelPHP.

if ($condition)

{

/ /  . . .

}

In place of ‘||’ and ‘&&’ use ‘or’ and ‘and’

In coding you can’t use ‘||’ and && but in place of these you have to use ‘or’ and ‘and’

/ / this is not applicable

if ($ var == false && $other_var != ‘some_value’)

/ / this is applicable

If ($ var == false and $other_var != ‘some_value’)

Priorities that are little different are shown by operators known as ‘and’ and ‘&&’

<?php

$var = 0;

if ($var = 2 && 1)  {

echo $var, PHP_EOL;  / /  => 1

}

$var = 0;

if ($var = 2 and 1)  {

echo $var, PHP_EOL;  / /  => 2

}

Here 1 is $var’s value and we have seen that $var = (2 && 1). It is interesting to know here that as compared to ‘=’, more priority is given to ‘&&’ and as compared to ‘and’, more priority is given to ‘=’. Apart from this 2 is $var’s value and we have seen that ($var = 2) and 1.

2. Standard of WordPress coding – For creating blogs you can use a PHP based software that is open source known as WordPress. WordPress is a framework that is fairly old. As compared to PSR a mindset of different types is followed by the standards of coding because on checking whether in PHP-FIG there is participation of developers of WordPress or not, we find that there is no participation.

For indents we can use Tabs

Instead of using spaces for indents, tabs need to be used by the coding standard of WordPress. Code lines can be lined up with the use of whitespaces.

[tab]$foo   =   ‘somevalue’;

[tab]$foo2 =   ‘somevalue2’;

[tab]$foo34   =   ‘somevalue3’;

[tab]$foo5 =   ‘somevalue4’;

If in the text editor you change the settings of tab width then with this, changing the width of indent will be possible without making any changes in the coding. As per the widths of the indent that are of different types, accommodating the preferences will be possible. For reducing the size of a file, you no longer need 4 whitespaces but a single tab will serve the purpose.

Correctly showing the tabs will not be possible for some environments. Dependencies on environment can be eliminated when for indents four spaces are recommended by PSR. For indents tabs can be used by the codes that are fairly old.

In Function Calls and Conditional Statements also we can use Whitespaces

for and if are the conditional statements and when using braces after or before these, a whitespace needs to be added.

if ( $condition ) {

/ /  . . .

}

In the calls and definitions of functions whitespaces need to be added by you.

function my_function( $arg1, $arg2 ) {

/ /   . . .

}

3. Standard of coding in Symfony – A web framework that is open source and fairly old is Symfony. There are some additional standards of PSR-2 and this PSR-2 is also followed by some basic standards. In PHP-FIG there is participation of developers. A mindset that is slightly different is followed by some standards which are additional.

For comparisons there are some notations known as Yoda notations

! ==, ! =, ===, == are used for doing comparisons. At the time of using these you can use Yoda notations.

/ /  recommended (called Yoda notations, or Yoda conditions)

if (null === $value)  {

/ /  . . .

}

/ /  not recommended (was recommended in CakePHP)

if ($value === null) {

/ /  . . .

}

If someone takes interest in creating custom websites then it will be good for him to contact a web development company.