-
Notifications
You must be signed in to change notification settings - Fork 551
Coding Standards
Arsalan Shah edited this page Jun 27, 2021
·
6 revisions
We don't believe in complex coding standards. There are alot of coding standards such a PSRx, Wordpress, FulePHP, CakePHP etc. We tried looked each of them and taken piece from each to create a simple standard for OSSN.
- Use Tabs instead of spaces.
- Use 1TBS (1 true brace) indentation style for Libraries. Use 2TBS for classes if possible otherwise 1TBS as you wish.
- First letter of class should be capital.
- Do not use closing php tags in end of any file.
- Align array elements on newline
- No space between control structure and bracket.
- Space between operators (logic, logical , bitwise, math. etc).
- Namespaces Usage.
- No space in start of any PHP file.
- No Use of $_GET, $_POST global variables.
Tabs are more reliable than spaces. Make sure to align the assignments of variables.
if(true){
}
function xyz(){
}
//variables assignments
$abc = 1;
$somelongvariable = 3;
$othervariable = 4;
class Abc {
}
You may use any array deceleration method but array() syntax is preferred to be used.
$array = array(
'abc',
'def',
);
if($def){
}
switch($x){
case 1:
break;
}
if($abc == 1 || $xyz == 'abc' && $xyz === true){
}
$abc = 2 + 10;
If you have to many classes and you think you would mess up or the others with your code, you may use Namespaces.
Make sure you don't have any special character or space in start of any PHP file.
Don't use these directly when writing components. Use the input() function.
$abc = $_GET['key']; //don't use this
$abc = input('key'); //use this.
Powered Open Source Social Network