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