I can't understand and find information why there are sometimes underscores in variable names, for example $_links
instead of $links
.
What does it mean?
The underscore in variable names is completely optional. Many programmers use it to differentiate private variables - so instance variables will typically have an underscore prepended to the name. This prevents confusion with local variables.
A single leading underscore in front of a variable, a function, or a method name means that these objects are used internally. This is more of a syntax hint to the programmer and is not enforced by the Python interpreter which means that these objects can still be accessed in one way on another from another script.
Variable names are case-sensitive. A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign " $ ", or the underscore character " _ ".
Underscores are used in two different ways in the Magento codebase.
In classes an underscore at the beginning of a variable or function name indicates that the variable is private or protected.
Within templates, most variables that are used locally are prefixed with an underscore. This indicates that the variable is "private" to the template.
Mostly this is done to protect your template vars from having collisions with view variables.
In Magento CE 1.9.x.x
Mage_Core_Block_Template::fetchView - ln 215 extract ($this->_viewVars, EXTR_SKIP);
See reference for extract function: function_extract.
Hope, it helped.
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