Annotation of embedaddon/php/ext/standard/tests/strings/str_split_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test str_split() function : usage variations - unexpected values for 'str' argument
3: --FILE--
4: <?php
5: /* Prototype : array str_split(string $str [, int $split_length])
6: * Description: Convert a string to an array. If split_length is
7: specified, break the string down into chunks each
8: split_length characters long.
9: * Source code: ext/standard/string.c
10: * Alias to functions: none
11: */
12:
13: echo "*** Testing str_split() : unexpected values for 'str' ***\n";
14:
15: // Initialise function arguments
16: $split_length = 3;
17:
18: //get an unset variable
19: $unset_var = 10;
20: unset ($unset_var);
21:
22: //defining class for object variable
23: class MyClass
24: {
25: public function __toString()
26: {
27: return "object";
28: }
29: }
30:
31: //resource variable
32: $fp = fopen(__FILE__, 'r');
33:
34: //different values for 'str' argument
35: $values = array(
36:
37: // int data
38: 0,
39: 1,
40: 12345,
41: -2345,
42:
43: // float data
44: 10.5,
45: -10.5,
46: 10.5e10,
47: 10.6E-10,
48: .5,
49:
50: // array data
51: array(),
52: array(0),
53: array(1),
54: array(1, 2),
55: array('color' => 'red', 'item' => 'pen'),
56:
57: // null data
58: NULL,
59: null,
60:
61: // boolean data
62: true,
63: false,
64: TRUE,
65: FALSE,
66:
67: // empty data
68: "",
69: '',
70:
71: // object data
72: new MyClass(),
73:
74: // undefined data
75: @$undefined_var,
76:
77: // unset data
78: @$unset_var,
79:
80: //resource data
81: $fp
82: );
83:
84: // loop through each element of $values for 'str' argument
85: for($count = 0; $count < count($values); $count++) {
86: echo "-- Iteration ".($count+1)." --\n";
87: var_dump( str_split($values[$count], $split_length) );
88: }
89:
90: //closing resource
91: fclose($fp);
92:
93: echo "Done";
94: ?>
95: --EXPECTF--
96: *** Testing str_split() : unexpected values for 'str' ***
97: -- Iteration 1 --
98: array(1) {
99: [0]=>
100: string(1) "0"
101: }
102: -- Iteration 2 --
103: array(1) {
104: [0]=>
105: string(1) "1"
106: }
107: -- Iteration 3 --
108: array(2) {
109: [0]=>
110: string(3) "123"
111: [1]=>
112: string(2) "45"
113: }
114: -- Iteration 4 --
115: array(2) {
116: [0]=>
117: string(3) "-23"
118: [1]=>
119: string(2) "45"
120: }
121: -- Iteration 5 --
122: array(2) {
123: [0]=>
124: string(3) "10."
125: [1]=>
126: string(1) "5"
127: }
128: -- Iteration 6 --
129: array(2) {
130: [0]=>
131: string(3) "-10"
132: [1]=>
133: string(2) ".5"
134: }
135: -- Iteration 7 --
136: array(4) {
137: [0]=>
138: string(3) "105"
139: [1]=>
140: string(3) "000"
141: [2]=>
142: string(3) "000"
143: [3]=>
144: string(3) "000"
145: }
146: -- Iteration 8 --
147: array(3) {
148: [0]=>
149: string(3) "1.0"
150: [1]=>
151: string(3) "6E-"
152: [2]=>
153: string(1) "9"
154: }
155: -- Iteration 9 --
156: array(1) {
157: [0]=>
158: string(3) "0.5"
159: }
160: -- Iteration 10 --
161:
162: Warning: str_split() expects parameter 1 to be string, array given in %s on line %d
163: NULL
164: -- Iteration 11 --
165:
166: Warning: str_split() expects parameter 1 to be string, array given in %s on line %d
167: NULL
168: -- Iteration 12 --
169:
170: Warning: str_split() expects parameter 1 to be string, array given in %s on line %d
171: NULL
172: -- Iteration 13 --
173:
174: Warning: str_split() expects parameter 1 to be string, array given in %s on line %d
175: NULL
176: -- Iteration 14 --
177:
178: Warning: str_split() expects parameter 1 to be string, array given in %s on line %d
179: NULL
180: -- Iteration 15 --
181: array(1) {
182: [0]=>
183: string(0) ""
184: }
185: -- Iteration 16 --
186: array(1) {
187: [0]=>
188: string(0) ""
189: }
190: -- Iteration 17 --
191: array(1) {
192: [0]=>
193: string(1) "1"
194: }
195: -- Iteration 18 --
196: array(1) {
197: [0]=>
198: string(0) ""
199: }
200: -- Iteration 19 --
201: array(1) {
202: [0]=>
203: string(1) "1"
204: }
205: -- Iteration 20 --
206: array(1) {
207: [0]=>
208: string(0) ""
209: }
210: -- Iteration 21 --
211: array(1) {
212: [0]=>
213: string(0) ""
214: }
215: -- Iteration 22 --
216: array(1) {
217: [0]=>
218: string(0) ""
219: }
220: -- Iteration 23 --
221: array(2) {
222: [0]=>
223: string(3) "obj"
224: [1]=>
225: string(3) "ect"
226: }
227: -- Iteration 24 --
228: array(1) {
229: [0]=>
230: string(0) ""
231: }
232: -- Iteration 25 --
233: array(1) {
234: [0]=>
235: string(0) ""
236: }
237: -- Iteration 26 --
238:
239: Warning: str_split() expects parameter 1 to be string, resource given in %s on line %d
240: NULL
241: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>