A little water a blog, excerpt from think PHP development specifications, is very guided, we can apply these specifications to the native PHP.
Naming conventions
The following naming conventions should be followed as far as possible during development with thinkphp:
- Class files are suffixed with. class.php (this refers to the class library file used internally by thinkphp, which does not represent an externally loaded class library file), is named with the Hump method, and capitalized, such as DbMysql.class.php;
- The namespace address of the class is the same as the path address, for example, the path where the Home\controller\usercontroller class should be application/home/controller/ UserController.class.php;
- Ensure that file naming and invocation are case-sensitive, because the case sensitivity is on top of Unix-like systems (while thinkphp is checked for capitalization even on Windows platforms under debug mode);
- The class name and file name are the same (including the same capitalization), for example, the file name of the Usercontroller class is UserController.class.php, and the Infomodel class name is InfoModel.class.php, and the class name of different class library has certain specification;
- Other class library files, such as functions, configuration files, and so on, are usually suffixed with. PHP (third party not required);
- The naming of functions uses lowercase letters and underscores, such as GET_CLIENT_IP;
- Methods are named using the Hump method, and the first letter lowercase or use underscore "_", such as getusername,_parsetype, usually the method that begins with an underscore belongs to the private method;
- Properties are named using the Hump method, and the first letter lowercase or use underscore "_", such as TableName, _instance, usually the underscore property belongs to the private property;
- A function or method that begins with a double underscore "__" as a magical method, such as __call and __autoload;
- Constants are named with uppercase letters and underscores, such as Has_one and Many_to_many;
- Configuration parameters are named with uppercase letters and underscores, such as html_cache_on;
- Language variables are named in uppercase letters and underscores, such as My_lang, where a language variable that starts with an underscore is usually used for system language variables, such as class_not_exist;
- There is no mandatory specification for the naming of variables, which can be carried out according to the team specification;
- The thinkphp template file is suffixed with. html By default (can be modified by configuration);
- Data tables and fields are named in lowercase and underlined, and note that field names do not start with an underscore, such as the Think_user table and the User_name field are correct, and data table fields such as _username may be filtered.
Exception: In thinkphp, there is a special case of a function name, which is a single-letter capitalization function, which is usually a shortcut to some operations, or a special function. For example: A, D, S, L methods, and so on, they have a special meaning, will be known later.
Since thinkphp is all using UTF-8 encoding by default, make sure that your program files are saved in UTF-8 encoded format and that the BOM header is removed (there are many ways to get rid of BOM header information, different editors have a setup method, you can use tools for unified detection and processing), Doing so may lead to many unexpected problems.
Development recommendations
In the process of developing with thinkphp, we offer the following recommendations that will make your development easier:
- Follow the framework's naming conventions and catalog specifications;
- In the development process as far as possible to open debugging mode, early detection problems;
- Look at the log files to find hidden problems;
- Develop a good habit of using the I function to get input variables;
- After updating or environment change, the first problem is emptying the runtime directory;
The naming specification and development suggestion of PHP from "thinkphp Development Specification"