It is easy to master PHP naming rules. When you are a beginner in PHP, you may encounter PHP naming problems. here we will introduce the naming rules of PHP, hoping to help you. careful friends can remember to keep them as future learning materials. 1. when you are new to PHP, you may encounter PHP naming problems. here we will introduce the naming rules for PHP, hoping to help you. careful friends can remember to keep them as future learning materials.
1. suitable PHP naming rules
Naming is the core of program planning. The ancients believed that as long as they knew the real name of a person, they would gain incredible power over that person. As long as you give things a correct name, it will give you and people later more powerful than the code. Don't laugh! The name is a long-term and profound result of a thing in its ecological environment. In general, only programmers who know the system can obtain the most appropriate name for the system. If all the names are suitable for their nature, the relationship is clear, and the meaning can be deduced. the assumption of the average person can also be expected.
If you find that only a few of your names can match their corresponding items, you 'd better look at your design again.
2. PHP naming rule class naming
Before naming a class, you must first know what it is. If you still cannot remember what the class is, your design is not good enough. A hybrid name composed of more than three words is easy to cause confusion between various entities of the system. let's look at your design and try to use it (CRC Session card) check whether the object corresponding to the name has so many functions. Naming a derived class should avoid the temptation to include its parent class name. The name of a class is only related to itself and has nothing to do with its parent class name. Sometimes suffix names are useful. for example, if your system uses an agent, you can name a part as the DownloadAgent for real information transfer.
3. PHP naming rules and functions
Generally, each method and function executes an action. Therefore, their names should clearly indicate what they do: replace ErrorCheck () with CheckForErrors () and DumpDataToFile () replace DataFile (). In this way, functions and data can also be differentiated.
Sometimes suffix names are useful:
◆ Max-indicates the maximum value that an object can assign.
◆ Cnt-the current value of a running counting variable.
◆ Key-Key value.
For example, RetryMax indicates the maximum number of retries, and RetryCnt indicates the current number of retries.
Sometimes prefix names are useful:
◆ Is-it means to ask a question about something. At any time, people will know that this Is a problem.
◆ Get-indicates obtaining a value.
◆ Set-meaning to Set a value
4. PHP naming rules do not use uppercase letters for all acronyms
In any of the following situations, you can use the upper-case letters and the lower-case letters in the first letter to represent the acronym. Use: GetHtmlStatistic. do not use: GetHTMLStatistic. reason: when the name contains acronyms, people seem to have a very different intuition. Unified rules are the best, so that the meaning of the name can be completely pre-known. Here is an example of NetworkABCKey. it is very confusing to note whether C in ABC or C in key. Some people don't care about this, but others hate it. So you will see different rules in different codes, so that you do not know how to call them.
For example:
- Class FluidOz // do not write it as FluidOZ
- Class GetHtmlStatistic // do not write it as GetHTMLStatistic
Bytes. 1 ....