When you first learn PHP, you may encounter PHP naming problems. Here we will introduce the PHP naming rules. I hope it can help everyone. Careful friends can write it down and keep it as future learning materials.
1. PHP Naming Rules Proper naming
Naming is the core of program planning. The ancients believed that knowing a person's true name would grant them incredible power over that person. As long as you think of the right names for things, it will give you and those who come after you more power than code. Don't laugh! A name is a long-lasting and far-reaching result of a thing in its ecological environment. In general, only programmers who understand the system can come up with the most appropriate name for the system. If all names are naturally appropriate, the relationship is clear, the meaning can be deduced, and ordinary people's inferences can be expected.
If you find that only a few of your names match their corresponding objects, it’s best to take a good look at your design again.
2. PHP Naming Rules Class Naming
Before naming a class, you must first know what it is. If you still can't remember what the class is based on the clues provided by the class name, then your design is not good enough. Mixed names consisting of more than three words can easily cause confusion between various entities in the system. Take another look at your design and try to use (CRC Session card) to see if the entity corresponding to the name has so many functions. When naming a derived class, you should avoid the temptation to include the name of its parent class. The name of a class is only related to itself and has nothing to do with the name of its parent class. Sometimes suffixes are useful. For example, if your system uses an agent, then name a component "DownloadAgent" to actually transmit information.
3. PHP Naming Rules Method and Function Naming
Usually each method and function performs an action, so their naming should clearly describe them What it does: Use CheckForErrors() instead of ErrorCheck(), and use DumpDataToFile() instead of DataFile(). Doing so also makes functions and data more distinguishable objects.
Sometimes suffixes are useful:
◆Max - meaning the maximum value that can be assigned to an entity.
◆Cnt - The current value of a running count variable.
◆Key - key value.
For example: RetryMax represents the maximum number of retries, and RetryCnt represents the current number of retries.
Sometimes prefixes are useful:
◆Is - meaning to ask a question about something. Whenever people see Is they know it's a problem.
◆Get - means to get a value.
◆Set - means setting a value
4. PHP naming rules abbreviations should not use all capital letters
For example:
<ol class="dp-xml"> <li class="alt"><span><span>class FluidOz // 不要写成 FluidOZ </span></span></li> <li class=""><span>class GetHtmlStatistic // 不要写成 GetHTMLStatistic </span></li> </ol>