Annotation of embedaddon/php/ext/standard/tests/array/array_key_exists_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_key_exists() function : usage variations - Pass differnt data types to $search arg
3: --FILE--
4: <?php
5: /* Prototype : bool array_key_exists(mixed $key, array $search)
6: * Description: Checks if the given key or index exists in the array
7: * Source code: ext/standard/array.c
8: * Alias to functions: key_exists
9: */
10:
11: /*
12: * Pass different data types as $search argument to array_key_exists() to test behaviour
13: */
14:
15: echo "*** Testing array_key_exists() : usage variations ***\n";
16:
17: // Initialise function arguments not being substituted
18: $key = 'val';
19:
20: //get an unset variable
21: $unset_var = 10;
22: unset ($unset_var);
23:
24: // get a class
25: class classA
26: {
27: public function __toString() {
28: return "Class A object";
29: }
30: }
31:
32: // heredoc string
33: $heredoc = <<<EOT
34: hello world
35: EOT;
36:
37: // get a resource variable
38: $fp = fopen(__FILE__, "r");
39:
40: // unexpected values to be passed to $search argument
41: $inputs = array(
42:
43: // int data
44: /*1*/ 0,
45: 1,
46: 12345,
47: -2345,
48:
49: // float data
50: /*5*/ 10.5,
51: -10.5,
52: 12.3456789000e10,
53: 12.3456789000E-10,
54: .5,
55:
56: // null data
57: /*10*/ NULL,
58: null,
59:
60: // boolean data
61: /*12*/ true,
62: false,
63: TRUE,
64: FALSE,
65:
66: // empty data
67: /*16*/ "",
68: '',
69: array(),
70:
71: // string data
72: /*19*/ "string",
73: 'string',
74: $heredoc,
75:
76: // object data
77: /*22*/ new classA(),
78:
79: // undefined data
80: /*23*/ @$undefined_var,
81:
82: // unset data
83: /*24*/ @$unset_var,
84:
85: // resource variable
86: /*25*/ $fp
87: );
88:
89: // loop through each element of $inputs to check the behavior of array_key_exists()
90: $iterator = 1;
91: foreach($inputs as $input) {
92: echo "\n-- Iteration $iterator --\n";
93: var_dump( array_key_exists($key, $input) );
94: $iterator++;
95: };
96:
97: fclose($fp);
98:
99: echo "Done";
100: ?>
101:
102: --EXPECTF--
103: *** Testing array_key_exists() : usage variations ***
104:
105: -- Iteration 1 --
106:
107: Warning: array_key_exists() expects parameter 2 to be array, integer given in %s on line %d
108: NULL
109:
110: -- Iteration 2 --
111:
112: Warning: array_key_exists() expects parameter 2 to be array, integer given in %s on line %d
113: NULL
114:
115: -- Iteration 3 --
116:
117: Warning: array_key_exists() expects parameter 2 to be array, integer given in %s on line %d
118: NULL
119:
120: -- Iteration 4 --
121:
122: Warning: array_key_exists() expects parameter 2 to be array, integer given in %s on line %d
123: NULL
124:
125: -- Iteration 5 --
126:
127: Warning: array_key_exists() expects parameter 2 to be array, double given in %s on line %d
128: NULL
129:
130: -- Iteration 6 --
131:
132: Warning: array_key_exists() expects parameter 2 to be array, double given in %s on line %d
133: NULL
134:
135: -- Iteration 7 --
136:
137: Warning: array_key_exists() expects parameter 2 to be array, double given in %s on line %d
138: NULL
139:
140: -- Iteration 8 --
141:
142: Warning: array_key_exists() expects parameter 2 to be array, double given in %s on line %d
143: NULL
144:
145: -- Iteration 9 --
146:
147: Warning: array_key_exists() expects parameter 2 to be array, double given in %s on line %d
148: NULL
149:
150: -- Iteration 10 --
151:
152: Warning: array_key_exists() expects parameter 2 to be array, null given in %s on line %d
153: NULL
154:
155: -- Iteration 11 --
156:
157: Warning: array_key_exists() expects parameter 2 to be array, null given in %s on line %d
158: NULL
159:
160: -- Iteration 12 --
161:
162: Warning: array_key_exists() expects parameter 2 to be array, boolean given in %s on line %d
163: NULL
164:
165: -- Iteration 13 --
166:
167: Warning: array_key_exists() expects parameter 2 to be array, boolean given in %s on line %d
168: NULL
169:
170: -- Iteration 14 --
171:
172: Warning: array_key_exists() expects parameter 2 to be array, boolean given in %s on line %d
173: NULL
174:
175: -- Iteration 15 --
176:
177: Warning: array_key_exists() expects parameter 2 to be array, boolean given in %s on line %d
178: NULL
179:
180: -- Iteration 16 --
181:
182: Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d
183: NULL
184:
185: -- Iteration 17 --
186:
187: Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d
188: NULL
189:
190: -- Iteration 18 --
191: bool(false)
192:
193: -- Iteration 19 --
194:
195: Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d
196: NULL
197:
198: -- Iteration 20 --
199:
200: Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d
201: NULL
202:
203: -- Iteration 21 --
204:
205: Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d
206: NULL
207:
208: -- Iteration 22 --
209: bool(false)
210:
211: -- Iteration 23 --
212:
213: Warning: array_key_exists() expects parameter 2 to be array, null given in %s on line %d
214: NULL
215:
216: -- Iteration 24 --
217:
218: Warning: array_key_exists() expects parameter 2 to be array, null given in %s on line %d
219: NULL
220:
221: -- Iteration 25 --
222:
223: Warning: array_key_exists() expects parameter 2 to be array, resource given in %s on line %d
224: NULL
225: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>