public static function safe_unserialize($string, $allowedClasses = [], $rethrow = false)
    {
        if (PHP_MAJOR_VERSION >= 7) {
            try {
                return unserialize($string, ['allowed_classes' => empty($allowedClasses) ? false : $allowedClasses]);
            } catch (\Throwable $e) {
                if ($rethrow) {
                    throw $e;
                }

                $logger = StaticContainer::get('Psr\Log\LoggerInterface');
                $logger->debug('Unable to unserialize a string: {message} (string = {string})', [
                    'message' => $e->getMessage(),
                    'backtrace' => $e->getTraceAsString(),
                    'string' => $string,
                ]);
                return false;
            }
        }

        return @unserialize($string);
    }
public static function safe_unserialize($string, $allowedClasses = [], $rethrow = false)
    {
        if (PHP_MAJOR_VERSION >= 7) {
            try {
                return unserialize($string, ['allowed_classes' => empty($allowedClasses) ? false : $allowedClasses]);
            } catch (\Throwable $e) {
                if ($rethrow) {
                    throw $e;
                }

                $logger = StaticContainer::get('Psr\Log\LoggerInterface');
                $logger->debug('Unable to unserialize a string: {message} (string = {string})', [
                    'message' => $e->getMessage(),
                    'backtrace' => $e->getTraceAsString(),
                    'string' => $string,
                ]);
                return false;
            }
        }

        return @unserialize($string);
    }
public static function safe_unserialize ( $ string , $ allowedClasses = [ ] , $ rethrow = false ) { if ( PHP_MAJOR_VERSION >= 7 ) { try { return unserialize ( $ string , [ 'allowed_classes' => empty ( $ allowedClasses ) ? false : $ allowedClasses ] ) ; } catch ( \ Throwable $ e ) { if ( $ rethrow ) { throw $ e ; } $ logger = StaticContainer :: get ( 'Psr\Log\LoggerInterface' ) ; $ logger -> debug ( 'Unable to unserialize a string: {message} (string = {string})' , [ 'message' => $ e -> getMessage ( ) , 'backtrace' => $ e -> getTraceAsString ( ) , 'string' => $ string , ] ) ; return false ; } } return @ unserialize ( $ string ) ; }
Secure wrapper for unserialize, which by default disallows unserializing classes

@param string $string String to unserialize
@param array $allowedClasses Class names that should be allowed to unserialize
@param bool $rethrow Whether to rethrow exceptions or not.
@return mixed
Secure wrapper for unserialize which by default disallows unserializing classes