Magento – How to Get All Values Currently in the Registry

registry

i've been using Mage::registry('current_category'); but i only found about that from a template done by someone else, so i am wondering if there is an easy way to get a list of all the registry keys/values currently being used in magento

while i'm not fussed if a link is provided with a list of magento ones i would like to get a list of any registry keys/values used in 3rd party modules

Best Answer

Sort of.

If you obey the intents of the Magento system designers, you can't see what's in the registry. That's because Magento's core engineers have declared the array that stores the registry values on the Mage class as private

static private $_registry        = array();

Also, there's no method in Mage for fetching the raw registry or all its keys. This means under normal operating conditions, the only methods allowed to access $_registry are in the class Mage. Since you can't rewrite anything in Mage, you're out of luck.

If you're willing to use reflection (and have PHP 5.3+ installed), you can use the following to grab the array

$class = new ReflectionClass('Mage');
$prop  = $class->getProperty('_registry');
$prop->setAccessible(true);        
$registry = $prop->getValue();
var_dump(  
    array_keys($registry)
);

This instantiates a ReflectionClass class, passing in Mage to tell PHP it's the defined Mage class we wish to reflect into.

Then we grab a ReflectionProperty object with getProperty, passing in _registry which tells PHP we want to reflect into the _registry property on the Mage class.

Then we use the setAccessible method to change the property from private to public, and then grab its value with getValue.