Like:
public
$foo = null,
$bar = 10;
protected
$_stuff = null,
$_moreStuff = 5;
A lot of people seem to do this. Why?
Isn’t this inconsistent naming (like some PHP functions are :))?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It really comes down to one thing: personal preference.
I, personally, am also one who uses that naming convention. Prefixing anything that is
protectedorprivatewith an underscore, be it a variable or a function, lets myself and any other programmer who I regularly work with know that that variable is global and will not be accessible outside of the current class/context.An example that helps clarify the use-case would be with class methods:
When I’m writing code that uses the class
Example, or working inside of the class itself, if I see_secondFunction()I will immediately know that it’s not a public function because of the starting_and thereby not accessible outside of the class; no need to go and find the actual function declaration and see the modifier. On the flip side, I will know thatfirstFunction()is public because it doesn’t begin with one.