Unserialize a value with error logging
@param string &$string On success, the portion used is removed
@return array ( bool $success, mixed $value )
435309
private static function unserializeValue( &$string ) {
		$error = null;
		set_error_handler( function ( $errno, $errstr ) use ( &$error ) {
			$error = $errstr;
			return true;
		} );
		$ret = unserialize( $string );
		restore_error_handler();

		if ( $error !== null ) {
			self::$logger->error( 'Value unserialization failed: ' . $error );
			return [ false, null ];
		}

		$serialized = serialize( $ret );
		$l = strlen( $serialized );
		if ( substr( $string, 0, $l ) !== $serialized ) {
			self::$logger->error(
				'Value unserialization failed: read value does not match original string'
			);
			return [ false, null ];
		}

		$string = substr( $string, $l );
		return [ true, $ret ];
	}
324527
public function unserialize($string)
    {
        $this->objectId = null;
        $this->setData([]);

        if ($string == '') {
            return;
        }

        $data = unserialize($string);
        if (is_array($data)) {
            $data = array_merge(['id' => null, 'data' => []], $data);
            $this->objectId = $data['id'];
            $this->objectData = $data['data'];
            unset($this->objectData['id']);
        }
    }
336756
protected function pkcs5_unpad($string)
    {
        $pad = ord($string{strlen($string)-1});
        if ($pad > strlen($string)) {
            return false;
        }

        if (strspn($string, chr($pad), strlen($string) - $pad) != $pad) {
            return false;
        }

        return substr($string, 0, -1 * $pad);
    }
1077568
function _getValue($string)
	{
		if (preg_match('/value=("([^"]*)"|\'([^\']*)\'|[^>\s]*)([^>]*)?>/is', $string, $match)) {
			$val_match = trim($match[1]);
			$val_match = trim($val_match, '"\'');
			unset($string);
			return $val_match;
		}
		return false;
	}
238976
public function unserialize($string)
    {
        $data = json_decode($string);
        foreach ($data as $property => $value) {
            $method = $this->setterName($property);

            if (is_numeric($value) && strstr($value, '.')) {
                $value = floatval($value);
            } elseif (is_object($value)) {
                if ($property == 'authorization_information') {
                    $object = new AuthorizationInformation();
                    $object->unserialize(json_encode($value));
                    $value = $object;
                } elseif ($property == 'payment_instrument') {
                    if (!isset($data->payment_method)) {
                        throw new Exception\Runtime('Property "payment_method" is missing');
                    }

                    switch ($data->payment_method) {
                        case Payment\Create::CARD:
                            $object = new PaymentInstrumentCard();
                            break;
                        case Payment\Create::RECURRING:
                            $object = new PaymentInstrumentRecurring();
                            break;
                        default:
                            $object = new PaymentInstrumentCard();
                            break;
                    }
                    $object->unserialize(json_encode($value));
                    $value = $object;
                }
            }

            $this->$method($value);
        }
    }
692261
private function doUnserialize($str)
    {
        $m = $this->allowedClasses ? @unserialize($str, [
            'allowed_classes' => $this->allowedClasses,
        ]) : @unserialize($str);

        if (false === $m) {
            $err = error_get_last();
            throw new SerializationError(sprintf(
                'Error unserializing message: %s', 
                $err && isset($err['message']) ? $err['message'] : 'unknown error'
            ));
        }

        return $m;
    }
556436
public static function Unserialize($SerializedString) {
		$Result = $SerializedString;
		
      if(is_string($SerializedString)) {
			if(substr_compare('a:', $SerializedString, 0, 2) === 0 || substr_compare('O:', $SerializedString, 0, 2) === 0)
				$Result = unserialize($SerializedString);
			elseif(substr_compare('obj:', $SerializedString, 0, 4) === 0)
            $Result = json_decode(substr($SerializedString, 4), FALSE);
         elseif(substr_compare('arr:', $SerializedString, 0, 4) === 0)
            $Result = json_decode(substr($SerializedString, 4), TRUE);
      }
      return $Result;
   }
849785
public static function unserialize($serialized)
    {
        // Set Handle
        set_error_handler(function () {
        }, E_ALL);
        $result = unserialize((string) $serialized);
        // Restores the previous error handler function
        restore_error_handler();
        if ($result === false) {
            return false;
        }
        return $result;
    }
623021
protected function unserialize($value)
    {
        $result = json_decode($value, true);
        if (is_null($result) && trim(strtolower($value)) !== 'null') {
            return (string)$value;
        }

        return $result;
    }
439301
protected function decode($string)
    {
        // decode if specified
        if (($pos = strpos($string, ':')) !== false) {
            if (!strncmp($string, 'base64', 6)) {
                return base64_decode(substr($string, 7));
            } elseif (!strncmp($string, 'urlencode', 9)) {
                return urldecode(substr($string, 10));
            }
        }

        return $string;
    }
399203
public function deserialize($string, array $options=[])
    {
        $value = $this->useOptions? @unserialize($string, $options) : @unserialize($string);

        if ($value !== false) {
            return $value === $this->serializeFalseAs ? false : $value;
        }

        // This does not work on hhvm
        if ($error = $this->unserializeError()) {
            throw new UnsupportedParameterException('Malformed serialized data: '.$error);
        }

        throw new UnsupportedParameterException('Unable to deserialize data');
    }
1034082
public static function decode($string)
    {
        if (! is_string($string)) {
            throw new JsonException('Json decode parameter must be a string');
        }

        $result = json_decode($string, true);

        if ($result === null) {
            throw new JsonException('Json decode error');
        }
        return $result;
    }
218191
public static function decode($string)
    {
        if (!is_string($string)) {
            throw new \InvalidArgumentException(sprintf(
                'Accept only string argument but got: "%s"',
                is_object($string) ? get_class($string) : gettype($string)
            ));
        }

        // PHP7 fix - empty string and null cause syntax error
        if (empty($string)) {
            return null;
        }

        $decoded = json_decode($string, true);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new \InvalidArgumentException(sprintf(
                'The malformed json given. Error %s and message %s',
                json_last_error(),
                json_last_error_msg()
            ));
        }

        return $decoded;
    }
45750
static public function sanitizeInjectively($string) {
        $sanitized = '';
        foreach (str_split($string) as $char) {
            $sanitized .= isset(self::$ALLOWED_CHARACTERS[$char]) ? $char : '='.base64_encode($char);
        }
        return $sanitized;
    }
268823
private static function decodeString($string)
    {
        $size = 0;
        $offset = 1;

        // Get some information on the first character.
        list($firstHex, $firstOctal) = self::analyzeFirstChar($string[0]);

        if (in_array(hexdec($firstOctal), array(10, 11))) {
            // fixstr
            $size   = hexdec($firstHex) - bindec('10100000');
            $offset = 1;
        } elseif ($firstHex === 'd9') {
            // str 8
            $size   = hexdec(unpack('H*', substr($string, 1, 1)));
            $offset = 2;
        } elseif ($firstHex === 'da') {
            // str 16
            $size   = hexdec(unpack('H*', substr($string, 1, 2)));
            $offset = 3;
        } elseif ($firstHex === 'db') {
            // str 32
            $size   = hexdec(unpack('H*', substr($string, 1, 4)));
            $offset = 5;
        }

        // Parse off the first $size characters and store it as the data.
        $string = substr($string, $offset);
        $data   = substr($string, 0, $size);
        $string = substr($string, $size);

        // Return
        return array($data, $string);
    }
900947
private function parse($string)
    {
        $params = explode(PHP_EOL, trim($string));
        $result = [];

        foreach ($params as $param) {
            $parts = explode(':', $param);
            $result[$parts[0]] = trim($parts[1]);
        }

        return $result;
    }
56491
protected function encode($string)
    {
        if (is_array($string)) {
            foreach ($string as $i => $value) {
                $string[$i] = $this->encode($value);
            }

            return $string;
        }

        if (is_scalar($string)) {
            return str_replace('%7E', '~', rawurlencode($string));
        }

        return null;
    }