3

Magento has an elegant way to override it's modules. But what I have done till now is override Blocks, Models, Helpers and controllers. But this file

Mage/Core/functions.php

doesn't appear to fall in any of those categories. Is there any elegant way to override this other than putting it in local codepool?

I want to change the error log messages(system and exception) and populate them with session and IP so that I can get a better knowledge about the users who received the errors.

  • 1
    just interested: can you give a little more detail what you need to achieve? – simonthesorcerer Oct 13 '15 at 14:31
  • I have edited my question – Brats Oct 13 '15 at 14:40
2

If I can see this correctly, Mage_Core_Model_App has this constant:

const DEFAULT_ERROR_HANDLER = 'mageCoreErrorHandler';

...which is later registered like this:

/**
 * Initialize PHP environment
 *
 * @return Mage_Core_Model_App
 */
protected function _initEnvironment()
{
    $this->setErrorHandler(self::DEFAULT_ERROR_HANDLER);
    date_default_timezone_set(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
    return $this;
}

You can override this class in a module and either change the constant to your custom method name, or modify _initEnvironment() to register another error handler.

==EDIT==

As pointed out in @Brat's comment, this function can not be overridden... however, here's an alternative approach. It's untested, and I have no idea if it can work :)

Referencing Alan Storm, these are the earliest events you can listen to:

resource_get_tablename    
core_collection_abstract_load_before
core_collection_abstract_load_after
controller_front_init_before

Maybe you can do something like this in your observer:

class Namespace_Module_Model_Observer {
    function customErrorHandler($o) {
        if(function_exists('mageCoreErrorHandler') {
            require_once(dirname(__FILE__) . '/../functions.php');
            Mage::app()->setErrorHandler("myErrorHandler");
        }
        return $this;
    }
}

Then place a file functions.php in app/code/local/Namespace/Module/functions.php and define myErrorHandler() there.

Or even another possibility: In the same observer, use runkit_function_remove() and re-define mageCoreErrorHandler() in your own functions.php-file.

  • Overriding Mage_Core_Model_App won't work. It's hardcoded in Mage.php – Brats Oct 14 '15 at 10:25
  • Updated my answer; untested, though – simonthesorcerer Oct 14 '15 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.