Reputation: 1385
I noticed that some people use variable names like these inside their classes:
private $_some_long_name_;
public static $_____foo___;
Why?
Shoudn't these variables be able to be accessed only trough class::variable
, $this->variable
or self::variable
? So you can't have a conflict between between them and other variables with the same name, right?
Upvotes: 1
Views: 258
Reputation: 30555
It's probably a habit from coding in earlier versions of PHP or even in other languages where the scope rules are more flexible.
Classes in PHP 4 supported neither private instance variables nor static variables. It was common for programmers to come up with naming conventions to help manage this. For the same reason, some programmers always prefix an underscore to all instance variables, even though it's not necessary.
Upvotes: 2
Reputation: 164742
Class property names match the same format restrictions of regular variables.
See http://www.php.net/manual/en/language.variables.basics.php
In relation to your question, people can name their class properties however they like however property names within the same class must be unique.
Upvotes: 1
Reputation: 18344
Because they don't want to confuse both variables accidentally. However, you're right, it's not necessary
Upvotes: 1