Last active
December 15, 2015 05:19
-
-
Save Andrewpk/5208024 to your computer and use it in GitHub Desktop.
codeLOLpt1. This is funny because in order to adequately catch errors of this function, you either need to register a new error handler and check within your handler, or parse $php_errormsg. Simply checking if unserialize returned false is not adequate, since false is an acceptable value to be serialized. IMO: unserialize should probably throw a…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$origErrorTrackVal = ini_set('track_errors',1); | |
$oldReportingLevel = error_reporting(E_ALL); //least reporting necessary is E_NOTICE | |
$mixedUnserializedVal = unserialize(($someArr['someIndex'])); | |
/** | |
* This next conditional is fun. At this point $mixedUnserializedVal can legally be any value except "unset" | |
* You still have to check the error messages though :-/ | |
*/ | |
if(isset($mixedUnserializedVal) && preg_match('/Undefined\sindex:\ssomeIndex/', $php_errormsg) === 0) { | |
//do work | |
} else { | |
//handle actual unserialize failure | |
} | |
$checkSetSucc = ini_set('track_errors',$origErrorTrackVal); | |
error_reporting($oldReportingLevel); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment