国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial http://67.220.92.14/forum/inde talks about very good PHP coding standards on page 1/3

http://67.220.92.14/forum/inde talks about very good PHP coding standards on page 1/3

Jul 29, 2016 am 08:37 AM

Note: This is the coding specification seen in the PHPCMS development documentation. Although it is called the PHPCMS development specification, I think all PHP programming should be like this. Having written so much PHP, I feel that a lot of coding is lacking in comparison with this standard. I must correct it in the future.
Phpcms Coding Standards
1. Introduction… 2
2. Scope of application… 2
3. The importance and benefits of standardization… 3
4. PHP coding specifications and principles… 3
4.1. Code markup… 3
4.2. Comments… 3
4.3. Writing rules… 4
4.3.1. Indentation… 4
4.3.2. Braces {}, if and switch. 4
4.3.3. Operators, parentheses, spaces, keys Words and functions… 5
4.3.4. Function definition… 6
4.3.5. Quotation marks… 6
4.3.6. Multi-language issues… 7
4.4. Naming principles… 8
4.4.1. Variable, object, function names … 8
4.4.2. Constants… 8
4.5. Initialization and logic checking of variables… 8
4.6. Security… 9
4.7. Compatibility… 9
4.8. Code reuse… 10
4.9. Other details… 10
4.9.1. Contains calls… 10
4.9.2. Error reporting levels… 11
5. Database design… 11
5.1. Fields… 11
5.1.1. Table and field naming… 11
5.1.2. Fields Structure… 11
5.2. SQL statement… 12
5.3. Performance and efficiency… 13
5.3.1. Fixed-length and variable-length tables… 13
5.3.2. Operation and retrieval… 13
5.3.3. Structure optimization and indexing Optimization… 14
5.3.4. Query optimization… 14
5.3.5. Compatibility issues… 16
6. Template design… 16
6.1. Code markup… 16
6.2. Writing rules… 16
6.2.1. HTML . 16
6.2.2. Variables… 16
6.2.3. Language elements… 17
6.2.4. Indentation… 17
7. Files and directories… 17
7.1. File naming… 17
7.2. Directory naming… 18
7.3. Empty directory index... 18
1. Introduction
This specification consists of programming principles, which integrates and refines the mature experience accumulated by developers over a long period of time, and is intended to help form a good and consistent programming style. In order to achieve twice the result with half the effort, this document will be updated from time to time if necessary.
Copyright: Shaanxi Jiushi Lulu Network Technology Co., Ltd., all rights reserved
Last update date: November 20, 2006
2. Scope of application
If no special instructions are given, the following rules and requirements are fully applicable to the phpcms project, and can also be used Most of them apply to other PHP projects in the company.
3. The Importance and Benefits of Standardization
When a software project tries to comply with public and consistent standards, it can make it easier for developers participating in the project to understand the code in the project and clarify the status of the program. It allows new participants to quickly adapt to the environment and prevents some participants from creating their own style and developing lifelong habits out of the need to save time, causing others to waste too much time and energy when reading. And in a consistent environment, the chance of coding errors can also be reduced. The disadvantage is that everyone has different standards, so it takes a while to adapt to and change your coding style, which temporarily reduces work efficiency. Considering the long-term healthy development of the project and higher team work efficiency in the later period, it is worthwhile to consider the temporary reduction in work efficiency, and it is also a process that must be gone through. Standards are not the key to project success, but they can help us be more efficient in team collaboration and complete established tasks more smoothly.
1. Programmers can understand any code and understand the status of the program
2. Newcomers can quickly adapt to the environment
3. It prevents new people who are new to PHP from creating their own style and developing it for life out of the need to save time. Habits
4. Prevent people who are new to PHP from making the same mistakes again and again
5. In a consistent environment, people can reduce the chance of making mistakes
6. Programmers have a consistent enemy
4. PHP coding standards With Principle
4.1. Code markup
PHP programs can use or to define PHP code. This form can be used when embedding pure variables in HTML pages.
In recent years, the PHP development team has been advocating code normalization and standardization. In future versions of PHP, this shorthand form may be deprecated or even canceled. Therefore, in order to enhance program compatibility, we will unify
4.2. Comments
Comments before release It is to add short introductory content to the code that is easy to forget its function. Please use C-style comments "/* */" and standard C++ comments "http://".
It is inevitable to leave some temporary code and debugging code during program development. Such code must be commented to avoid forgetting it in the future. All temporary, debugging, and experimental code must add a unified comment mark "http://debug" followed by complete comment information. This makes it easier to batch check whether there are any doubtful problems in the program before the program is released and final debugging. code. For example:
$num = 1;
$flag = TRUE; //debug It is not sure whether $flag needs to be assigned a value here
if(empty($flag)) {
//Statements
}
4.3. Writing rules
4.3 .1. Indentation
The unit of each indentation is one TAB (8 blank characters wide), which needs to be set by each developer participating in the project in the editor (UltraEdit, EditPlus, Zend Studio, etc.). To prevent formatting irregularities caused by forgetting when writing code.
This indentation specification applies to functions, classes, logical structures, loops, etc. in PHP and JavaScript.
4.3.2. Braces {}, if and switch
The first bracket goes with the keyword, and the last bracket goes with the keyword in the same column;
In the if structure, if and elseif go with the two parentheses before and after, one space on the left and right, all Braces are placed on a separate line. In addition, even if there is only one line of statement after the if, braces still need to be added to ensure a clear structure;
In the switch structure, usually when a case block is processed, the subsequent case block processing will be skipped, so in most cases it is necessary to add a break . The position of break depends on the program logic. It can be on the same line as case or on a new line. However, in the same switch body, the position format of break should be consistent.
The following are examples that comply with the above specifications:
If ($condition)
{
switch ($var)
{
case 1: echo 'var is 1'; break;
case 2: echo 'var is 2'; break ;
default: echo 'var is neitherither 1 or 2'; break;
}
}
else
{
switch ($str)
{
case 'abc':
$result = 'abc';
break;
default:
$result = 'unknown';
break;
}
}
4.3.3. Operators, parentheses, spaces, keywords and functions
Each operator must be separated from the values ??or expressions involved in the operation on both sides There is a space. The only exception is that there are no spaces on both sides of the character concatenation operator;
The left bracket "(" should be closely connected with the function keyword. Otherwise, a space should be used to separate the "(" from the previous content;
Right bracket Except for brackets ")" followed by ")" or ".", all other brackets are separated by spaces;
Unless specifically required in strings, under normal circumstances, two consecutive spaces do not appear in programs and HTML;
Under no circumstances should blank lines with TAB or spaces appear in PHP programs, that is, such blank lines should not contain any TAB or spaces. At the same time, no extra TAB or spaces can appear at the end of any program line. Most editors have the function of automatically removing spaces at the end of lines. If the habit is not developed well, you can use it temporarily to avoid unnecessary spaces;
For each large program body, a blank line and two program blocks should be added above and below Only use one blank line between them, multiple lines are prohibited.
Divide the program blocks as reasonably as possible. Too large or too small divisions will affect others' reading and understanding of the code. Generally, it can be divided by larger function definition, logical structure, and functional structure. Program blocks with less than 15 lines do not need to add blank lines;
In the description or display part, if the content contains mixed Chinese, numbers, and English words, spaces should be added before and after the numbers or English words.
Based on the above principles, the following examples illustrate the correct writing format:
$result = (($a + 1) * 3 / 2 + $num)).'Test';
$condition ? func1($var) : func2( $var);
$condition ? $long_statement
: $another_long_statement;
if ($flag)
{
//Statements
//More than 15 lines
}
Showmessage('Please use the restore.php tool to restore data.' );

Current page 1/3 123Next page

The above introduces the 1/3 page of the very good PHP coding specification at http://67.220.92.14/forum/inde, including the content at http://67.220.92.14/forum/inde. I hope it will be helpful to the PHP tutorial. Interested friends help.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
PHP Variable Scope Explained PHP Variable Scope Explained Jul 17, 2025 am 04:16 AM

Common problems and solutions for PHP variable scope include: 1. The global variable cannot be accessed within the function, and it needs to be passed in using the global keyword or parameter; 2. The static variable is declared with static, and it is only initialized once and the value is maintained between multiple calls; 3. Hyperglobal variables such as $_GET and $_POST can be used directly in any scope, but you need to pay attention to safe filtering; 4. Anonymous functions need to introduce parent scope variables through the use keyword, and when modifying external variables, you need to pass a reference. Mastering these rules can help avoid errors and improve code stability.

How to handle File Uploads securely in PHP? How to handle File Uploads securely in PHP? Jul 08, 2025 am 02:37 AM

To safely handle PHP file uploads, you need to verify the source and type, control the file name and path, set server restrictions, and process media files twice. 1. Verify the upload source to prevent CSRF through token and detect the real MIME type through finfo_file using whitelist control; 2. Rename the file to a random string and determine the extension to store it in a non-Web directory according to the detection type; 3. PHP configuration limits the upload size and temporary directory Nginx/Apache prohibits access to the upload directory; 4. The GD library resaves the pictures to clear potential malicious data.

Commenting Out Code in PHP Commenting Out Code in PHP Jul 18, 2025 am 04:57 AM

There are three common methods for PHP comment code: 1. Use // or # to block one line of code, and it is recommended to use //; 2. Use /.../ to wrap code blocks with multiple lines, which cannot be nested but can be crossed; 3. Combination skills comments such as using /if(){}/ to control logic blocks, or to improve efficiency with editor shortcut keys, you should pay attention to closing symbols and avoid nesting when using them.

How Do Generators Work in PHP? How Do Generators Work in PHP? Jul 11, 2025 am 03:12 AM

AgeneratorinPHPisamemory-efficientwaytoiterateoverlargedatasetsbyyieldingvaluesoneatatimeinsteadofreturningthemallatonce.1.Generatorsusetheyieldkeywordtoproducevaluesondemand,reducingmemoryusage.2.Theyareusefulforhandlingbigloops,readinglargefiles,or

Tips for Writing PHP Comments Tips for Writing PHP Comments Jul 18, 2025 am 04:51 AM

The key to writing PHP comments is to clarify the purpose and specifications. Comments should explain "why" rather than "what was done", avoiding redundancy or too simplicity. 1. Use a unified format, such as docblock (/*/) for class and method descriptions to improve readability and tool compatibility; 2. Emphasize the reasons behind the logic, such as why JS jumps need to be output manually; 3. Add an overview description before complex code, describe the process in steps, and help understand the overall idea; 4. Use TODO and FIXME rationally to mark to-do items and problems to facilitate subsequent tracking and collaboration. Good annotations can reduce communication costs and improve code maintenance efficiency.

Learning PHP: A Beginner's Guide Learning PHP: A Beginner's Guide Jul 18, 2025 am 04:54 AM

TolearnPHPeffectively,startbysettingupalocalserverenvironmentusingtoolslikeXAMPPandacodeeditorlikeVSCode.1)InstallXAMPPforApache,MySQL,andPHP.2)Useacodeeditorforsyntaxsupport.3)TestyoursetupwithasimplePHPfile.Next,learnPHPbasicsincludingvariables,ech

How to access a character in a string by index in PHP How to access a character in a string by index in PHP Jul 12, 2025 am 03:15 AM

In PHP, you can use square brackets or curly braces to obtain string specific index characters, but square brackets are recommended; the index starts from 0, and the access outside the range returns a null value and cannot be assigned a value; mb_substr is required to handle multi-byte characters. For example: $str="hello";echo$str[0]; output h; and Chinese characters such as mb_substr($str,1,1) need to obtain the correct result; in actual applications, the length of the string should be checked before looping, dynamic strings need to be verified for validity, and multilingual projects recommend using multi-byte security functions uniformly.

Quick PHP Installation Tutorial Quick PHP Installation Tutorial Jul 18, 2025 am 04:52 AM

ToinstallPHPquickly,useXAMPPonWindowsorHomebrewonmacOS.1.OnWindows,downloadandinstallXAMPP,selectcomponents,startApache,andplacefilesinhtdocs.2.Alternatively,manuallyinstallPHPfromphp.netandsetupaserverlikeApache.3.OnmacOS,installHomebrew,thenrun'bre

See all articles