public function decode($input)
    {
        set_error_handler(__CLASS__ . '::onError');
        $value = json_decode($input, true);
        restore_error_handler();

        if (($value === null) && (strtolower(trim($input)) !== 'null')) {
            $valuePhp = self::getValuePhp($input);
            throw new ErrorException("Invalid JSON: {$valuePhp}");
        }

        if (!$this->getReply($value, $output)) {
            $valuePhp = self::getValuePhp($input);
            throw new ErrorException("Invalid JSON-RPC 2.0 response: {$valuePhp}");
        }

        return $output;
    }