I needed a way to detect if some values were serialized or not, annoyingly PHP does not provide a method for this. I’d also rather not perform unserialize() on everything to check for a serialized string in the name of efficiency, so instead I came up with a simple function to detect serialized data. The result of my endeavours is a function that checks a string for basic makers of the PHP serialization form, it only checks the variables type and not any deeper values inside arrays or objects, if this preliminary testing is successful then unserialize() is invoked to provide the final proof. The unserialized form is available as an option argument passed by reference and the return value is a boolean, true for boolean or false otherwise. You can find the function on Gist or below. (more…)
