Home  >  Article  >  Backend Development  >  What is the camel case naming of php?

What is the camel case naming of php?

黄舟
黄舟Original
2017-11-14 09:22:413994browse

Camel case naming method is when the variable name or function name is a unique identifier composed of one or more words connected together, the first word starts with Start with a lowercase letter; Camel case namingThe first letter of the second word is capitalized or the first letter of each word is capitalized, for example: myFirstName, myLastName. Such variable names look like camel humps. , hence the namehump naming.

In order to make it easier for programmers to communicate their code among peers, they adopt a unified naming method that is more readable. For example: some programmers like all lowercase letters, and some programmers like to use underscores, so if they want to write a variable with my name, their common writing methods are myname, my_name, MyName or myName. Such naming rules are not suitable for all programmers to read, and using camel case naming can increase the readability of the program.

The word Camel-Case comes from the mixed-case format commonly used in the Perl language, and the cover of the best-selling book "Programming Perl" (O'Reilly Publishing) written by Larry Wall et al. The picture is exactly that of a camel.

The naming rule of camel case can be regarded as a convention, not absolute or mandatory, in order to increase recognition and readability.

For example, here is the same function named using camel notation and underline notation:

printEmployeePaychecks();
print_employee_paychecks();

The first function name uses camel notation Nomenclature - each logical breakpoint in the function name is marked with an uppercase letter; the second function name uses the underscore method - each logical breakpoint in the function name is marked with an underscore.
Camel-style nomenclature has become more and more popular in recent years. It is used quite a lot in many new function libraries and environments such as Microsoft Windows. On the other hand, the underscore method became popular after the emergence of c. It is very commonly used in many old programs and environments such as UNIX.

Camel case method (small camel case method)
Variables are generally identified with small camel case method. CamelCase means capitalizing the first letter of every word except the first word. For example,

int myStudentCount;


The first word of the variable myStudentCount is all lowercase, and the first letter of the following words is capitalized.

Pascal method (large camel case method)
Compared with the small camel case method, the large camel case method also capitalizes the first letter of the first word. Commonly used in class names, function names, attributes, namespace. For example

publicclass DataBaseUser;

So when working, you should pay attention to your own naming standards and strictly demand yourself according to camel case naming!

Related recommendations:

Yii2 How to use camel case naming to access controller instances

Yii2 Use camel case naming to access Instance analysis of controller

JS naming convention: Hungarian nomenclature or camel case

The above is the detailed content of What is the camel case naming of php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn