How to find out which getter methods are available
-
29-09-2020 - |
Question
Often I'm working on a Magento template or block and while looking for a variable I try to use a getter method.
I use xDebug so normally I just go through the debugger and find what I need and guess the getter method, and usually it works. for example:
$this->getProduct()->getId();
But sometimes I can't find the getter method and use xDebug with PHPStorm to evaluate the expression for the value I need.
This usually gives me an expression like the below:
$program['type']->_data['special_url_key']
While this works it does not seem to be the best way to do it, I've tried using $program->getType();
but it doesn't work.
Am I missing something? The example above is from a custom module, I thought with Magento's Magic Getter & Setter methods it should still work. Although, looking at this module the block in question inherits or extends from Mage_Core_Block_Template
Solution
It looks like $program
is neither an instance of Varien_Object
nor an object at all, thus no overloading methods are available.
$program['type']->getSpecialUrlKey()
might work if the array has an entry with the key type
that is an instance of Varien_Object
.
To make a developer's life easier, classes that offer "magic" methods should be annotated accordingly, see Mage_Sales_Model_Order
for example.