<?php
function sugar_unserialize($value)
{
preg_match('/[oc]:\d+:/i', $value, $matches);
if (count($matches)) {
return false;
}
return unserialize($value);
}
$test1 = 'O:8:"stdClass":0:{}';
$test2 = 'O:+8:"stdClass":0:{}';
var_dump(sugar_unserialize($test1), sugar_unserialize($test2));
- Output for 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
- Warning: unserialize(): Error at offset 0 of 20 bytes in /in/oc2cY on line 11
bool(false)
bool(false)
- Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26
- Notice: unserialize(): Error at offset 0 of 20 bytes in /in/oc2cY on line 11
bool(false)
bool(false)
- Output for 7.3.32 - 7.3.33
- bool(false)
bool(false)
- Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.30, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33
- bool(false)
object(stdClass)#1 (0) {
}
- Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9
- bool(false)
object(stdClass)(0) {
}
preferences:
103.62 ms | 411 KiB | 5 Q