I ran into an issue today at work that was a pain to track down so I thought I would put it out there for anyone who may run into it.
For a quick background, I made a poor choice when designing my WordPress plugin. I chose to store my complex class objects by serializing them into the options table. This, as opposed to storing the data in a simple format and recreating them on each request. It’s caused me issues due to this issue here, as well as others.
We’re also using memcached as our object cache, so options get cached between requests. The problem is my plugin (which defined my class) was being loaded before I ever called
get_options() as it was supposed to. But wordpress loads all options with
autoload = "yes" into an
$alloptions global for quick-access. This happens earlier in the request, before plugins are loaded.
This was so difficult to track down because while the damage was done early in the request, the fatal error didn’t occur until I tried to access a property of the object. WordPress happily and quietly loaded
$alloptions up with an incomplete object (since its class hadn’t been defined yet) and when I used
get_option to fetch it it was being returned from there.