Why we declare some variables in PHP as like $_variablename
?
Does _
define something?
Please help me to clear this up, thanks.
The underscore does not mean that the variable is private. It is not necessary to use the underscore. It’s simply a naming convention that reminds the developer that the variable/property/method is either private or protected
For Example
// This variable is not available outside of the class
private $_someVariable;
class MyClass {
// This method is only available from within this class, or
// any others that inherit from it.
protected function __myFunction() {}
}
In the code above, the underscore is not what makes the variable or method private; the private/protected keyword does that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With