Home > Article > Backend Development > Personal summary of PHP coding standards_PHP tutorial
1. At the head of the original code or class, indicate the author and key algorithm calculation process
For example
/**
*@author zengmoumou
*Function: According to the list IP, obtain the operator, province, city, and county corresponding to the IP
*/
2. Try to use a combination of English words for variables, with the first one lowercase and the last one capitalized
For example:
$confTreeModel = D("ConfTree");
3. Try to use a combination of English words for function names, with the first one lowercase and the last one capitalized
For example:
function searchRealServer($keyword)
4. It is best to write the author, variables, and algorithm of the function above the function
For example:
/**
* @author zengmoumou
* Get the searched result switch
* Enter description here ...
* @param unknown_type $allIds
*/
Private function getSwitchsInIds($allIds) {
5. Try not to exceed 100 lines of function. If it exceeds, split it as appropriate
6. Independent functional original code is best divided into configuration page, function page and business page.
For example, a small development that reads the database and does summary.
Can be split into
config.php configuration page [Write database configuration, etc.]
function.php Function page [Write various functions with independent functions, such as reading data functions, constructing report functions, and sending email functions]
statWeekData.php business page [refer to the configuration page, function page, and call various functions in order to process the business logic]