4

we get an error message like this at the very bottom of our home page

Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'Mage_Core_Model_Config_Element' is not allowed' in [no active file] on line 0

now the problem is that we can't tell what file is trying to serialize the mentioned class, however the page loads fine and the error seems to disappear when the caches are on

does anyone know how we can debug this

10

It is quite famous error.

It means that somewhere you save object of SimpleXMLElement class (or its child) to the session. In your particular case it is Mage_Core_Model_Config_Element class.

When script ends his work, php tries to save all objects from $_SESSION array to the session file and tries to serialize $_SESSION array. Unfortunately, SimpleXMLElement can't be serialized because it wraps a libxml resource type. Resources cannot be serialized in php.

Probably, you are doing somewhere something like Mage::getSingleton('core/session')->setXXX(Mage::getConfig()->getNode('...')). Mage_Core_Model_Config::getNode() returns Mage_Core_Model_Config_Element, not just string.

So, you need to find this place and either add (string) type cast or use Mage::getStoreConfig('...').

3

If there is no active file, I would say it is an error_handler, exception_handler, register_shutdown_function or __sleep

Just search through the code what happens in thee functions, whether a handler is registered, etc.

2

I used the following code to track down which part of the session was causing the problem. Get this as late in the processing of the page as possible, probably somewhere in footer.phtml or the bottom of your page template.

function tloc_is_iterable($var) {
    return (is_array($var) || $var instanceof Traversable);
}

function tloc_find_unserializable($var, $tab=false) {
    if (!$tab) {
        $tab = "\t";
    }

    if (tloc_is_iterable($var)) {
        foreach ($var as $key => $each) {
            if (is_resource($each)) {
                echo $tab . '<span style="color: #090;">'.$key.'</span> -> Resource' . "\n";
            } else {
                try {
                    serialize($each);

                    // if serialization doesn't error
                    echo $tab . '<span style="color: #090;">'.$key.'</span>' . "\n";
                } catch (Exception $e) {
                    echo $tab . '<span style="color: #f40;">';
                    if (!tloc_is_iterable($each)) {
                        echo '<strong><i>' . $key . '</i></strong>';
                    } else {
                        echo $key;
                    }

                    echo '</span>';
                    if (is_object($each)) {
                        echo ' -> '.get_class($each);
                    }
                    echo "\n";
                }
            }

            if (tloc_is_iterable($each)) {
                tloc_find_unserializable($each, $tab."\t");
            }
        }
    }
}


echo '<pre style="background-color: #fff; color: #000;">';
tloc_find_unserializable($_SESSION);
echo '</pre>';

Hopefully you'll see some things in red. Find the inner-most tabbed item in red and search your codebase for that. For instance, in my case I found that 'last_category' was set to a model that can't be serialized, so I searched for setLastCategory and found a 3rd party module that was adding a model to the session.

If you can't find the inner-most tabbed item in red, move up the tree searching for each item in red in your codebase until you find where it's being added to the session.

Hope this helps.

1

Workaround:

I had Cache disabled (System -> Cache Management).

Enabling Cache did solve the issue for me.

  • This saved my day! – Vaisakh Pc Apr 27 '18 at 7:05

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.