indeed magic methods

Magento and the PHP world that I am trying to learn is full of surprises, in my way to replicate (made it better:) ) the Dashboard (and more) functionality using magenots API I have found methods that I wasn’t able to locate source for, and this time I have searched everywhere. As I don’t like to bang the wall with my head I have asked someone with greater knowledge and experience then me, his answer was short but concise. PHP has the “magic” methods two of those are __get and __set, any undefined instance variables are going through those. Magento is using this feature, in Varien_Object class you can find them and learn that actually use of them were marked as deprecated(?), anyway any call to undefined instance property through those magic functions are tunnelled to getData/setData methods.


$collection = Mage::getResourceModel('reports/order_collection')
    ->calculateSales(1);
		
$collection->load();
		
$item = $collection->getFirstItem();

print_r($item->getLifetime());
//is equal to
print_r($item->getData("lifetime"));

happy coding

This entry was posted in magento, php and tagged , , . Bookmark the permalink.