Home > Backend Development > PHP Tutorial > What is the special significance of variables and functions whose general names begin with an underscore in PHP?

What is the special significance of variables and functions whose general names begin with an underscore in PHP?

WBOY
Release: 2016-08-18 09:16:00
Original
1972 people have browsed it

What are the special meanings of variables and functions whose names begin with an underscore in PHP?

I often see this usage in other people’s frameworks, but what are the benefits of doing so?

Reply content:

What are the special meanings of variables and functions whose names begin with an underscore in PHP?

I often see this usage in other people’s frameworks, but what are the benefits of doing so?

The framework starts variable names and function names with _ to avoid conflicts with names used by users.

You can also indicate private methods or properties by starting with _.

Can be found at:

The meaning of variables starting with an underscore in PHP

Look at PHP naming conventions and development suggestions from "ThinkPHP Development Specifications"

One underscore is a private variable and a private method
Two underscores are PHP built-in variables.

Things starting with an underscore represent private members of the class.
This is just an unwritten rule. The only benefit is to enhance readability. As soon as you see anything starting with an underscore, it is a private member.

It should be borrowed from other languages, such as c++, java.

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template