/** * Decide on the best acceptable hash algorithm we have available for hash() * @return string A hash algorithm */ public static function hashAlgo() { if (!is_null(self::$algo)) { return self::$algo; } $algos = hash_algos(); $preference = ['whirlpool', 'sha256', 'sha1', 'md5']; foreach ($preference as $algorithm) { if (in_array($algorithm, $algos)) { self::$algo = $algorithm; return self::$algo; } } // We only reach here if no acceptable hash is found in the list, this should // be a technical impossibility since most of php's hash list is fixed and // some of the ones we list are available as their own native functions // But since we already require at least 5.2 and hash() was default in // 5.1.2 we don't bother falling back to methods like sha1 and md5. throw new DomainException("Could not find an acceptable hashing function in hash_algos()"); }