Standard writing code in PHP
Each company has different encryption standards based on their practical standards. Encryption standards are necessary because there may be many developers working on different modules, so if they start inventing their own standards, then the source code will become very unmanageable. and it will become difficult to maintain source code in the future.
Each company will have different code standards based on their work practices. Code standards are necessary because there may be many programmers working on different modules, so if they start inventing their own standards, then the source code will become a difficult, difficult stack. manage and difficult to maintain source code in the future.
Here are the reasons why code code must be used:
- Programmers working with you must understand the code you created. A common code standard acts as a blueprint for all members participating in that project in the team.
- Simplicity and clarity can be achieved by proper code will help you reduce common mistakes.
- Not once written code is done, sometimes you will have to see, edit your code, with the standard code agreed before, you will easily understand the code you have written, the view / edit also more advantageous.
- Its industry standards follow a specific standard to get better quality in software.
Here are some guidelines you should follow when writing code in PHP programming:
Indentation and line length - Create indentation by pressing 4 times the space bar (space bar) and do not use any tab keys because different computers use different settings for the tab key. For the length of the code line, you should keep the line of code about 75-85 characters long, which makes your code more readable.
Control structure - It includes if, for, while, switch , . Between these keywords and the opening parenthesis, there should be a space (press once) to distinguish them from function calls. You are strongly encouraged to always use curly braces whenever possible.
For example
if ((điều_kiện 1 ) || (điều_kiện 2 )) { hành động cần thực thi 1 ; } elseif ((điều_kiện 3 ) && (điều_kiện 4 )) { hành động cần thực thi 2 ; } else { default hành động cần thực thi mặc định ; }
You can write switch commands as follows:
switch (thing_kale) {
case 1:
Action to execute
break;
case 2:
Action to execute
break;
default:
default action
break;
}
Call to function - When calling the function, between the function name, the opening and first parentheses should be written immediately, without spaces; Add a space between a comma and each parameter, and there is no space between the last parameter, closing brackets and semicolons. Here's an example:
$ var = foo ($ bar, $ baz, $ quux);
Function definition - Declare the function by "BSD / Allman style".
function fooFunction ($ arg1, $ arg2 = '') {
if (thing_kien) {
command to execute
}
return $ val;
}
Comment - Comment in C (/ /) language and in C ++ (//) standard both OK. The use of Perl / shell (#) style comments is not recommended.
PHP code card - Always use To determine the scope of PHP code, do not use abbreviations .
Variable name:
- Use all is lowercase.
- Use underscores (_) as a delimiter.
- Global variables (global) should be added before a "g".
- Global constants should be uppercase with the separator character underscores (_).
- Static variables should be added before an "s".
Creating Reentrant functions - Functions should not contain static variables but prevent a function from being reentrant.
Align declarative blocks - The declaration block should be aligned.
One command per line - There should only be one statement per line, unless the statements are very closely related.
Short functions and methods - Methods should be limited to one code page.
There may be many guidelines, other rules are mentioned when writing code in PHP. Ideally, all these rules and guidelines should be consistent throughout the code process and this only happens when you follow certain code standards. You can have your own standard if you like to make a difference.
Follow tutorialspoint
Previous article: Upload File in PHP
Next article: Variable predefined in PHP
You should read it
- JavaScript functions
- PHP functions
- How to Create and Call PHP Functions
- How to use functions in Less CSS
- Functions in Python
- Save time with these text formatting functions in Microsoft Excel
- What is Low-Code? And how does it work?
- FUNCTION (Function) in SQL Server
- Inline function in C ++
- LEN function in SQL Server
- How to use the LEN function in Excel
- Load the operator stack to call the function () in C ++
Maybe you are interested
How the Orion spacecraft is being protected from extreme radiation Camera wifi - New trends in 2019 'Imitate' China, the US will deploy dense camera system, a surveillance camera 4 people How to choose a CCTV surveillance camera Model of Fujifilm surveillance camera with the ability to zoom in and out of a person from more than 2km away What to consider when buying surveillance cameras for families