Summery Summery

Compare two strings, in constant-time.

Syntax Syntax

ParagonIE_Sodium_Compat::compare( string $left, string $right )

Description Description

Compared to memcmp(), compare() is more useful for sorting.

Parameters Parameters


(Required) The left operand; must be a string


(Required) The right operand; must be a string

Return Return

(int) If < 0 if the left operand is less than the right If = 0 if both strings are equal If > 0 if the right operand is less than the left

Source Source

File: wp-includes/sodium_compat/src/Compat.php

    public static function compare($left, $right)
        /* Type checks: */
        ParagonIE_Sodium_Core_Util::declareScalarType($left, 'string', 1);
        ParagonIE_Sodium_Core_Util::declareScalarType($right, 'string', 2);

        if (self::useNewSodiumAPI()) {
            return (int) sodium_compare($left, $right);
        if (self::use_fallback('compare')) {
            return (int) call_user_func('\\Sodium\\compare', $left, $right);
        return ParagonIE_Sodium_Core_Util::compare($left, $right);



Leave a Reply