File size: 1,452 Bytes
1e94262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--TEST--
Hash: hash_equals() test
--FILE--
<?php

function trycatch_dump(...$tests) {
    foreach ($tests as $test) {
        try {
            var_dump($test());
        }
        catch (\Error $e) {
            echo '[' . get_class($e) . '] ' . $e->getMessage() . "\n";
        }
    }
}

trycatch_dump(
    fn() => hash_equals("same", "same"),
    fn() => hash_equals("not1same", "not2same"),
    fn() => hash_equals("short", "longer"),
    fn() => hash_equals("longer", "short"),
    fn() => hash_equals("", "notempty"),
    fn() => hash_equals("notempty", ""),
    fn() => hash_equals("", ""),
    fn() => hash_equals(123, "NaN"),
    fn() => hash_equals("NaN", 123),
    fn() => hash_equals(123, 123),
    fn() => hash_equals(null, ""),
    fn() => hash_equals(null, 123),
    fn() => hash_equals(null, null),
);

?>
--EXPECT--
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(true)
[TypeError] hash_equals(): Argument #1 ($known_string) must be of type string, int given
[TypeError] hash_equals(): Argument #2 ($user_string) must be of type string, int given
[TypeError] hash_equals(): Argument #1 ($known_string) must be of type string, int given
[TypeError] hash_equals(): Argument #1 ($known_string) must be of type string, null given
[TypeError] hash_equals(): Argument #1 ($known_string) must be of type string, null given
[TypeError] hash_equals(): Argument #1 ($known_string) must be of type string, null given