PHP Coding Specification _php

Source: Internet
Author: User
1. Introduction
1.1. Importance of Standardization * *
The problem of standardization in some ways gives everyone a headache and makes everyone feel that they are in the same position. This helps to keep these recommendations evolving across many projects, and many companies spend weeks arguing by word-by-phrase. Standardization is not a special personal style, it is completely open to local improvement.
1.2. Advantages
When a project tries to comply with common standards, there are the following benefits:
· Programmers can learn any code to understand the state of the program
· New people can quickly adapt to the environment
· Prevent new access to PHP from the time-saving needs, create a set of style and develop lifelong habits
· Prevent new people from contacting PHP making the same mistakes again and again
· In a consistent environment, people can reduce the chance of making mistakes.
· The programmers have a consistent enemy.
1.3. Disadvantages
· Because standards are made by people who don't know PHP, standards usually look silly.
· Because the standard is not the same as I do, so the standard usually looks stupid.
· Standards Reduce creativity
· Standards are not necessary for long-term co-operation among people
· The standard forces too many formats
1.4. Discussion
The experience of many projects has led to the conclusion that the adoption of programming standards can make the project more smoothly accomplished. Is the standard the key to success? Of course not. But they can help us, and we need all the help we can get! To be honest, much of the controversy over a standard of detail stems mainly from conceited thinking. Few decisions about a reasonable standard can be said to be a lack of technology, which is just the reason for the taste. So, be flexible and take control of your ego, and remember that any project depends on team work.
1.5. Explanation
1.5.1. Standard implementation
You should first identify all the most important elements within the development team, perhaps the criteria are not appropriate for your situation. It may have summed up important issues, and there may be some strong objections to some of those issues. No matter under what circumstances, as long as the final success, people will mature understand that the standard is reasonable, and then other procedures will find its reasonable * *, and feel that with some reservations to follow this standard is worthwhile. If there is no voluntary cooperation, the requirements can be established: standards must be tested by the code. Without testing, the solution is just a bunch of ridiculous people based on an imprecise base.
1.5.2. Identity view
1. This is not feasible;
2. It may be possible, but it is neither practical nor boring;
3. This is true, and I have told you;
4. This is what I thought first;
5. That should have been the case.
If you look at things with negative stereotypes, keep your mind open. You can still make it a nonsense conclusion, but the way to make a conclusion is that you have to be able to accept different ideas. Please give yourself a little time to do it.
1.5.3. Four stages of a project
1. Database structure
2. Design
3. Data layer
4. HTML Layer

2. Naming rules

2.1. Proper naming

Naming is the core of program planning. The ancients believed that knowing a person's real name would gain an incredible power over that person. As long as you think of the right name for something, it will give you and later people a stronger power than the code. Don't laugh!
A name is a long and far-reaching result of things in the ecological environment in which they are located. In general, only the programmer who understands the system can get the most appropriate name for the system. If all the names are compatible with their nature, then the relationship is clear, meaning can be deduced, and the general presumption can be expected.
If you find that only a small amount of your name can match its counterpart, it's best to take a good look at your design again.

2.2. Class naming

· Before you name a class, you must first know what it is. If you still can't figure out what this class is, then you're not doing a good job with the kind of clues that the class name provides.
· A mix of more than three words is prone to confusion among entities of the system, and then look at your design and try to use the CRC Session card to see if the named entity has so many functions.
· The name of the derived class should avoid the temptation to take its parent class name, which is related only to itself and not to what its parent class is called.
· Sometimes the suffix is useful, for example: If your system uses a proxy (agent), then a part is named "Download Agent" (downloadagent) to actually transmit the information.

2.3. Methods and function naming

· Usually each method and function performs an action, so naming them should clearly explain what they do: Replace Errorcheck () with Checkforerrors () and Dumpdatatofile () instead of datafile (). Doing so can also make the function and data a more distinguishable object.
· Sometimes the suffix name is useful:
o max-meaning the maximum value that an entity can give.
o Cnt-The current value of a running count variable.
O Key-key value.
For example: Retrymax represents the maximum number of retries, and retrycnt represents the current number of retry attempts.
· Sometimes the prefix name is useful:
O is-meaning to ask a question about something. Whenever people see is, they know it's a problem.
o get-meaning to get a value.
o set-meaning to set a value
For example: Ishitretrylimit.

2.4. Do not use uppercase letters in all abbreviations

· In any case, you can use the first letter to capitalize the remaining lowercase letters to represent abbreviations in lieu of all uppercase letters.
Use: Gethtmlstatistic.
Not used: gethtmlstatistic.
Reason
· When names contain acronyms, people seem to have very different instincts. Uniform rules are the best, so that the meaning of naming can be fully predictable.
As an example of networkabckey, note that C is the C in the ABC or in the key, which is very confusing. Some people don't care about this, others hate it. So you'll see different rules in different code, so you don't know how to call it.
For example
Class Fluidoz//Do not write Fluidoz
Class Gethtmlstatistic//Do not write gethtmlstatistic

2.5. Class naming

· Use uppercase letters as a separation of words, and all other letters in lowercase
· The first letter of the first name uses uppercase
· Do not use underscores ('_')
Reason
· According to many naming methods, most people think this is the best way.
For example
Class Nameonetwo
Class Name

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.