A detailed explanation of PHP variable naming rules

Source: Internet
Author: User
Tags arrays learn php lowercase naming convention php programming uppercase letter

PHP variable naming rules

1. The variable begins with the dollar sign $. such as $name, $age.

2, dollar sign $ The first character that follows cannot be a number, only an underscore _ or a letter. Variables such as $1_1 are wrong.

3, in addition to the underscore _, the variable does not allow any space or punctuation. This means that the variable name can only contain: A-Z, A-Z, 0-9, and underscore _.

4, the PHP variable name is case-sensitive. such as $name and $name are two different variables.

PHP variable naming rules the rest of the considerations

1. When you use two or more words to name a variable, you can capitalize the first letter of all words except the first word. such as $myname, $yourFamilyName.

2, the following underlined _ start the named variable usually represents a special variable. such as creating protected properties in a class, PHP predefined variables ($_get), global arrays, and so on.

3. When defining variables, do not covet brevity, but use descriptive names to define variables.

To learn without thinking is to be reckless, but to think without learning is perilous. Hope you learn PHP on the road smooth sailing, and become a master of the PHP programming Arts.


The above is the entire contents of the PHP variable naming rules. The following is nonsense, if you have time, might as well read roughly, perhaps you can resonate.

PHP variable naming rules

From the beginning of the university to now, land has continued to contact a variety of programming languages. such as client language Javascript,actionscript, server-side language c++,java,asp.net,php, and so on. Of all these languages, I want to learn PHP the most. Not for anything else, just because of the reading of PHP: Fart h fart, said catchy, full of charm. Today I saw the PHP variable naming rules This section, simply just write a little things, talk to pass the boring time.

Learning about PHP has been intermittent. The ambition to learn PHP well in my youth is now almost gone.

Some people say that in such a society, no one can live spotless. What kind of society is this? I'm not quite sure. But I heard that it was a deaf man who heard the mute say that the blind man saw the age of love. Not completely, but I can't believe it at all.

In any case, since it is not easy to live, then live and cherish it.

PHP is what I want to cherish.

So, today I turned over a book borrowed from the library--php Dynamic Web Design (second edition, author David Powers).

See the PHP Variable naming convention section. These very basic content, after a lapse of several years to review, it is really warm to know the new feeling.

In order to make the impression more profound, but also in order to practice, good memory than rotten written truth, in this restless night, I decided to write this article, dedicated to have wanted to become a master of Php himself.

1. The variable begins with the dollar sign $. such as $name, $age;

2, dollar sign $ the first character after the can not be a number;

3, in addition to the underscore _, the variable does not allow any space or punctuation;

4, the PHP variable name is case-sensitive. such as $name and $name are two different variables.

Remaining considerations

1. When you use two or more words to name a variable, you can capitalize the first letter of all words except the first word. such as $myname; $yourFamilyName;

2, the following underlined _ start the named variable is usually left to special circumstances to use. such as creating a protected property in a class; PHP predefined variables: Global arrays, and so on;

3. When defining variables, do not covet brevity, but use descriptive names to define variables.


Example

The same function is named after the camel-style and the Underline method respectively:

Printemployeepaychecks ();
Print_employee_paychecks ();

The first function name uses the camel-named Method--each logical breakpoint in the function name is marked with an uppercase letter; the second function name uses an underscore----each logical breakpoint in the function name is marked with an underscore.
Camel-style nomenclature has become increasingly popular in recent years, and it is used quite a lot in environments such as many new functions libraries and Microsoft Windows. On the other hand, the underline method is popular after the advent of C, and in many old programs and UNIX environments, it is used very widely.

Edit this paragraph application overview

Camel-style nomenclature (camel-case) is a set of naming rules (conventions) when a computer program is written.
Camel-style nomenclature is when the variable name or function name is connected by one or more words,, the first word begins with a lowercase letter, and the initial letter of the second word or the first letter of each word is capitalized, for example: MyFirstName, Mylastname, Such variable names appear to be like camel peaks, hence the name.
Camel-style nomenclature (camel-case) comes from a commonly used case-mixed format in the Perl language, while the cover picture of the best-selling book "Programming Perl" (O ' Reilly published) by Larry Wall is just a camel.
The naming rules of camel-style nomenclature can be regarded as a convention and are not absolute or mandatory in order to increase recognition and readability.

Hump Method (Small Hump method)

The variable is usually identified by small hump method. The Hump method means that the first letter of a word is capitalized except for the first word. Such as
int mystudentcount;
Variable Mystudentcount The first word is all lowercase, followed by the first letter of the word uppercase.

Pascal method (Large Hump method)

Compared to the small hump method, the big hump method capitalizes the first letter of a word. Commonly used for class names, function names, attributes, namespaces. For example,
Publicclass databaseuser;

Related Article

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.