1--TEST--
2Test array_key_exists() function : usage variations -  equality test for certain data types
3--FILE--
4<?php
5/*
6 * Pass certain data types that can be taken as a key in an array
7 * and test whether array_key_exists(() thinks they are equal and therefore
8 * returns true when searching for them
9 */
10
11echo "*** Testing array_key_exists() : usage variations ***\n";
12
13$unset = 10;
14unset($unset);
15$array = array ('null' => null,
16                'NULL' => NULL,
17                'empty single quoted string' => '',
18                "empty double quoted string" => "",
19                'undefined variable' => @$undefined,
20                'unset variable' => @$unset);
21
22//iterate through original array
23foreach($array as $name => $input) {
24    $iterator = 1;
25    echo "\n-- Key in \$search array is : $name --\n";
26    $search[$input] = 'test';
27
28    //iterate through array again to see which values are considered equal
29    foreach($array as $key) {
30        echo "Iteration $iterator:  ";
31        var_dump(array_key_exists($key, $search));
32        $iterator++;
33    }
34    $search = null;
35}
36
37echo "Done";
38?>
39--EXPECT--
40*** Testing array_key_exists() : usage variations ***
41
42-- Key in $search array is : null --
43Iteration 1:  bool(true)
44Iteration 2:  bool(true)
45Iteration 3:  bool(true)
46Iteration 4:  bool(true)
47Iteration 5:  bool(true)
48Iteration 6:  bool(true)
49
50-- Key in $search array is : NULL --
51Iteration 1:  bool(true)
52Iteration 2:  bool(true)
53Iteration 3:  bool(true)
54Iteration 4:  bool(true)
55Iteration 5:  bool(true)
56Iteration 6:  bool(true)
57
58-- Key in $search array is : empty single quoted string --
59Iteration 1:  bool(true)
60Iteration 2:  bool(true)
61Iteration 3:  bool(true)
62Iteration 4:  bool(true)
63Iteration 5:  bool(true)
64Iteration 6:  bool(true)
65
66-- Key in $search array is : empty double quoted string --
67Iteration 1:  bool(true)
68Iteration 2:  bool(true)
69Iteration 3:  bool(true)
70Iteration 4:  bool(true)
71Iteration 5:  bool(true)
72Iteration 6:  bool(true)
73
74-- Key in $search array is : undefined variable --
75Iteration 1:  bool(true)
76Iteration 2:  bool(true)
77Iteration 3:  bool(true)
78Iteration 4:  bool(true)
79Iteration 5:  bool(true)
80Iteration 6:  bool(true)
81
82-- Key in $search array is : unset variable --
83Iteration 1:  bool(true)
84Iteration 2:  bool(true)
85Iteration 3:  bool(true)
86Iteration 4:  bool(true)
87Iteration 5:  bool(true)
88Iteration 6:  bool(true)
89Done
90