Skip to content

Instantly share code, notes, and snippets.

@Andrewpk
Last active December 15, 2015 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andrewpk/5208024 to your computer and use it in GitHub Desktop.
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…
<?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