3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sugar_unserialize($value) { preg_match('/[oc]:\d+:/i', $value, $matches); if (count($matches)) { return false; } return unserialize($value); } $test1 = 'a:1:{i:0;O:8:"stdClass":0:{}}'; $test2 = 'a:1:{i:0;O:+8:"stdClass":0:{}}'; var_dump(sugar_unserialize($test1), sugar_unserialize($test2));
Output for 8.3.0 - 8.3.9
Warning: unserialize(): Error at offset 9 of 30 bytes in /in/5vaj9 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.29, 8.2.0 - 8.2.21
Notice: unserialize(): Error at offset 9 of 30 bytes in /in/5vaj9 on line 11 bool(false) bool(false)
Output for 7.3.32 - 7.3.33
bool(false) bool(false)
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
bool(false) array(1) { [0]=> object(stdClass)#1 (0) { } }

preferences:
243.02 ms | 404 KiB | 336 Q