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       // float data
32/*2*/  'float' => array(
33       10.5 => 'positive',
34       -10.5 => 'negative',
35       .5 => 'half',
36       ),
37
38/*3*/  'extreme floats' => array(
39       12.3456789000e6 => 'large',
40       12.3456789000E-10 => 'small',
41       ),
42
43       // null data
44/*4*/ 'null uppercase' => array(
45       NULL => 'null 1',
46       ),
47
48/*5*/  'null lowercase' => array(
49       null => 'null 2',
50       ),
51
52       // boolean data
53/*6*/ 'bool lowercase' => array(
54       true => 'lowert',
55       false => 'lowerf',
56       ),
57
58/*7*/  'bool uppercase' => array(
59       TRUE => 'uppert',
60       FALSE => 'upperf',
61       ),
62
63       // empty data
64/*8*/ 'empty double quotes' => array(
65       "" => 'emptyd',
66       ),
67
68/*9*/  'empty single quotes' => array(
69       '' => 'emptys',
70       ),
71
72       // string data
73/*10*/ 'string' => array(
74       "stringd" => 'stringd',
75       'strings' => 'strings',
76       $heredoc => 'stringh',
77       ),
78
79       // undefined data
80/*11*/ 'undefined' => array(
81       @$undefined_var => 'undefined',
82       ),
83
84       // unset data
85/*12*/ 'unset' => array(
86       @$unset_var => 'unset',
87       ),
88);
89
90// loop through each element of $inputs to check the behavior of key()
91$iterator = 1;
92foreach($inputs as $key => $input) {
93  echo "\n-- Iteration $iterator : $key data --\n";
94  while (key($input) !== NULL) {
95    var_dump(key($input));
96    next($input);
97  }
98  $iterator++;
99};
100?>
101--EXPECT--
102*** Testing key() : usage variations ***
103
104-- Iteration 1 : int data --
105int(0)
106int(1)
107int(12345)
108int(-2345)
109
110-- Iteration 2 : float data --
111int(10)
112int(-10)
113int(0)
114
115-- Iteration 3 : extreme floats data --
116int(12345678)
117int(0)
118
119-- Iteration 4 : null uppercase data --
120string(0) ""
121
122-- Iteration 5 : null lowercase data --
123string(0) ""
124
125-- Iteration 6 : bool lowercase data --
126int(1)
127int(0)
128
129-- Iteration 7 : bool uppercase data --
130int(1)
131int(0)
132
133-- Iteration 8 : empty double quotes data --
134string(0) ""
135
136-- Iteration 9 : empty single quotes data --
137string(0) ""
138
139-- Iteration 10 : string data --
140string(7) "stringd"
141string(7) "strings"
142string(11) "hello world"
143
144-- Iteration 11 : undefined data --
145string(0) ""
146
147-- Iteration 12 : unset data --
148string(0) ""
149