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?
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
.