1--TEST--
2Test key() function : usage variations
3--FILE--
4<?php
5/*
6 * Pass arrays where keys are different data types as $array_arg to key() to test behaviour
7 */
8
9echo "*** Testing key() : usage variations ***\n";
10
11//get an unset variable
12$unset_var = 10;
13unset ($unset_var);
14
15// heredoc string
16$heredoc = <<<EOT
17hello world
18EOT;
19
20// unexpected values to be passed as $array_arg
21$inputs = array(
22
23       // int data
24/*1*/  'int' => array(
25       0 => 'zero',
26       1 => 'one',
27       12345 => 'positive',
28       -2345 => 'negative',
29       ),
30
31       // null data
32/*4*/ 'null uppercase' => array(
33       NULL => 'null 1',
34       ),
35
36/*5*/  'null lowercase' => array(
37       null => 'null 2',
38       ),
39
40       // boolean data
41/*6*/ 'bool lowercase' => array(
42       true => 'lowert',
43       false => 'lowerf',
44       ),
45
46/*7*/  'bool uppercase' => array(
47       TRUE => 'uppert',
48       FALSE => 'upperf',
49       ),
50
51       // empty data
52/*8*/ 'empty double quotes' => array(
53       "" => 'emptyd',
54       ),
55
56/*9*/  'empty single quotes' => array(
57       '' => 'emptys',
58       ),
59
60       // string data
61/*10*/ 'string' => array(
62       "stringd" => 'stringd',
63       'strings' => 'strings',
64       $heredoc => 'stringh',
65       ),
66
67       // undefined data
68/*11*/ 'undefined' => array(
69       @$undefined_var => 'undefined',
70       ),
71
72       // unset data
73/*12*/ 'unset' => array(
74       @$unset_var => 'unset',
75       ),
76);
77
78// loop through each element of $inputs to check the behavior of key()
79$iterator = 1;
80foreach($inputs as $key => $input) {
81  echo "\n-- Iteration $iterator : $key data --\n";
82  while (key($input) !== NULL) {
83    var_dump(key($input));
84    next($input);
85  }
86  $iterator++;
87};
88?>
89--EXPECT--
90*** Testing key() : usage variations ***
91
92-- Iteration 1 : int data --
93int(0)
94int(1)
95int(12345)
96int(-2345)
97
98-- Iteration 2 : null uppercase data --
99string(0) ""
100
101-- Iteration 3 : null lowercase data --
102string(0) ""
103
104-- Iteration 4 : bool lowercase data --
105int(1)
106int(0)
107
108-- Iteration 5 : bool uppercase data --
109int(1)
110int(0)
111
112-- Iteration 6 : empty double quotes data --
113string(0) ""
114
115-- Iteration 7 : empty single quotes data --
116string(0) ""
117
118-- Iteration 8 : string data --
119string(7) "stringd"
120string(7) "strings"
121string(11) "hello world"
122
123-- Iteration 9 : undefined data --
124string(0) ""
125
126-- Iteration 10 : unset data --
127string(0) ""
128