PHP naming rules-PHP Tutorial-php Tutorial

Source: Internet
Author: User
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:

 
 
  1. Class FluidOz // do not write it as FluidOZ
  2. Class GetHtmlStatistic // do not write it as GetHTMLStatistic

Bytes. 1 ....

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.