PHP Fatal error: Invalid serialization data for DateTime object at session_start()

We have a WordPress plugin which sometimes experiences a problem where the page is blank and no amount of refresh/reset will work – the only thing that solves it is to close and restart the browser and thereby force a new session.

The error I get in the logs is

Read More
PHP Fatal error:  Invalid serialization data for DateTime object in /path/to/my/file on line 15

The line refers to my session class. The class is simply a wrapper class for an array of data which is then saved in the normal PHP session. The line number refers to a line in the constructor for the session class in which we run session_start. Specifically:

if (!session_id()) {
    session_start(); //This is the line from the error logs
}

We do have a class in our plugin which extends DateTime and we do store such objects in the session, but the error is not the one I would expect if we had called session_start too early – apart from anything else it refers to DateTime, not our class at all. It could of course be something that WordPress or another plugin has put in the session. It only appears to happen sometimes and loading the same page in a new sesion is then OK.

Running PHP 5.4.21 in a LAMP stack with WordPress 3.7.1

Any ideas?

Related posts

Leave a Reply

1 comment