Underscores in magento variables - magento

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?

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.

variables starting with $_ are usually used as member attributes of a class or inside phtml template files, while others are mostly used as local variables inside a class method.

Related

Variables in double parentheses in YAML file

I am working on a pipeline and bumped into YAML file with multiple variables inserted with double parentheses, e.g. ((project_name)). Google surprisingly was not helpful with that. What can it mean/do? Based on studying the repository some of them refer to the global variables in the config directory, some however are nowhere to be found. Thanks for help, I am new to YAML!

What do you call variables that have double curly braces in laravel

I'm trying to find out a name for code that is surrounded by double curly braces in Laravel.
Do they even have a name. Are they known as double curly braces in all languages.
The reason I want to know is that I still do not quite understand the scope of them. I know a lot of languages use them, but what is their name?
For instance; if I want to know why double curly brace variables don't work in a Laravel #include; how do I find out?
Another example is that I cannot add a tag on stack exchange for double-curly-braces because it does not exist.
Searching Google brings up nothing.
Searching stack exchange is the same.
I call them "blade template variables."
Behind the scene of {{ $foo }} is <?php echo e($foo); ?>. I accidentally found out when I'm searching a particular variable in my project using PhpStorm and it shows me the compiled view files of Laravel w/c resides in storage/framework/views.

Restructured text (rst) http links underscore ('__' vs '_' use)

With restructured text, I've seen both these used:
`Some Link <http://www.some.com>`_
`Some Link <http://www.some.com>`__
Both generate the same output from Sphinx,
Whats the difference between using _ or a double underscore __ for http URL links?
Why would you one over another?
In short, if its a one-off (anonymous) URL which you don't intend to reference, use double underscore.
In practice you could use either in most cases, they generate the same HTML output for example.
However, using single underscores for links means that by default you're creating a reference target - which could conflict with other references of the same name.
So this for example will warn:
.. _Thing:
Title
=====
Text with `Thing <http://link.com>`_.
WARNING: Duplicate target name, cannot be used as a unique reference: "thing".
While this could be overlooked in most cases, it could make for confusing situations especially for anyone inexperienced with reStructuredText. So you may prefer to avoid this entirely only defining targets when that is your intention.
According to:
http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#anonymous-hyperlinks
With a single trailing underscore, the reference is named and the same target URI may be referred to again. With two trailing underscores, the reference and target are both anonymous, and the target cannot be referred to again. These are "one-off" hyperlinks.
There are examples on the page links.

Is there a limit in the length of Magento Classes?

I found an unexpected issue while attempting to load a block within a magento module. The block name was *Mycompany_CustomerModule_Block_CustomerModuleDashboardDataBlock* (yes, the name is very long, but I added the module name all blocks related to the module to avoid confusing a dashboard.html with the one used by Magento Core).
The issue is that, if I try to load such block, with the following command:
$this->getLayout()->createBlock('customermodule/customermoduledashboarddatablock')
Magento raises the exception "Invalid block type". I couldn't figure out what was wrong, since I copied the whole file from a block that works perfectly, and then I tried renaming the block to something shorter, such as simply DashboardDataBlock. With the shorter name, block is loaded correctly.
My question is, therefore, are there any limitations in the length of Classes' names? I can always shorten the class name, but I'd like to know if there are limits so that I can avoid having similar issues in the future. Thanks.
The problem is, regardless of file system case-sensitivity, that the last part of Magento class name must not be camel cased.
MyNamespace_MyModule_MyClassName NO
MyNamespace_MyModule_myclassname NO
MyNamespace_MyModule_myclassName NO
MyNamespace_MyModule_Myclassname YES
MyNamespace_MyModule_My_Class_Name YES
You will notice this pattern in core modules, too. Class prefixes of namespace and module are read from the configuration files and can contain arbitrary upper case letters. But the actual class names are derived from the class alias in a way that does not allow upper case letters (have a look at the code in Mage_Core_Model_Config::getGroupedClassname() if you want to know, why. Hint: it uses uc_words)
There could be a couple of things at play here. If you are on a case-sensitive filesystem, then the issue is that you need to match camelCasing between your filename and class ID (customermoduledashboarddatablock in your case), with the note that the first letter of any folder or file which is resoled by the autoloader will need to be uppercase regardless of class prefix or class ID. Additionally, note that PHP does not care about casing of class names and method calls - only the autoloader cares, and only on case-sensitive filesystems.
The other possible issue could be total filename length in a Windows environment.

Using Apache and mod_ext_filter, need to dynamically replace values of static file based off of query string

I've got a situation where I need to alter the contents of a cached file based off of one of the query string arguments passed in. I'd love to use sed to do a simple regular expression replacement of a value based off of said argument but I can't figure that one out. I could use a ruby script to do the replacement for me but can't seem to access the query string for the request within the script. The documents for mod_ext_filter say:
In addition to the standard CGI environment variables, DOCUMENT_URI, DOCUMENT_PATH_INFO, and QUERY_STRING_UNESCAPED will also be set for the program.
Um yeah, can't seem to access those.
Has anybody any experience with this or does anybody have a better solution?
Doh! Looks like I simply need to access the ENV variable within ruby. Pretty dumb of me.
Using PHP scripting language server function we can able to get the query string values.
echo $_SERVER['REQUEST_URI'];
And pass the URL arguments as a variable to the file and make it dynamic.
Refer : PHP.net

Resources