1--TEST--
2Test str_repeat() function
3--INI--
4precision=14
5--FILE--
6<?php
7/* Prototype: string str_repeat ( string $input, int $multiplier );
8   Description: Returns input repeated multiplier times. multiplier has to be
9     greater than or equal to 0. If the multiplier is set to 0, the function
10     will return an empty string.
11*/
12
13echo "*** Testing str_repeat() with possible strings ***";
14$variations = array(
15  'a',
16  'foo',
17  'barbazbax',
18  "\x00",
19  '\0',
20  NULL,
21  TRUE,
22  4,
23  1.23,
24  "",
25  " "
26);
27
28/* variations in string and multiplier as an integer */
29foreach($variations as $input) {
30  echo "\n--- str_repeat() of '$input' ---\n" ;
31  for($n=0; $n<4; $n++) {
32    echo "-- after repeating $n times is => ";
33    echo str_repeat($input, $n)."\n";
34  }
35}
36
37/* variations in multiplier as well as string to be repeated. Same variant
38   values are used as string to be repeated as well as multiplier */
39echo "\n\n*** Testing str_repeat() with various strings & multiplier value ***";
40foreach ( $variations as $input ) {
41  echo "\n--- str_repeat() of '$input' ---\n" ;
42  foreach ( $variations as $multiplier ) {
43    echo "-- after repeating '$multiplier' times is => ";
44    var_dump( str_repeat($input, $multiplier) );
45  }
46}
47
48
49echo "\n*** Testing str_repeat() with complex strings containing
50       other than 7-bit chars ***\n";
51$str = chr(0).chr(128).chr(129).chr(234).chr(235).chr(254).chr(255);
52var_dump(str_repeat($str, chr(51)));  // ASCII value of '3' given
53var_dump(str_repeat($str, 3));
54
55
56echo "\n\n*** Testing error conditions ***";
57var_dump( str_repeat() );  // Zero args
58var_dump( str_repeat($input[0]) );  // args < expected
59var_dump( str_repeat($input[0], 3, 4) );  // args > expected
60var_dump( str_repeat($input[0], -1) );  // Invalid arg for multiplier
61
62echo "Done\n";
63?>
64--EXPECTF--
65*** Testing str_repeat() with possible strings ***
66--- str_repeat() of 'a' ---
67-- after repeating 0 times is =>
68-- after repeating 1 times is => a
69-- after repeating 2 times is => aa
70-- after repeating 3 times is => aaa
71
72--- str_repeat() of 'foo' ---
73-- after repeating 0 times is =>
74-- after repeating 1 times is => foo
75-- after repeating 2 times is => foofoo
76-- after repeating 3 times is => foofoofoo
77
78--- str_repeat() of 'barbazbax' ---
79-- after repeating 0 times is =>
80-- after repeating 1 times is => barbazbax
81-- after repeating 2 times is => barbazbaxbarbazbax
82-- after repeating 3 times is => barbazbaxbarbazbaxbarbazbax
83
84--- str_repeat() of '�' ---
85-- after repeating 0 times is =>
86-- after repeating 1 times is => �
87-- after repeating 2 times is => ��
88-- after repeating 3 times is => ���
89
90--- str_repeat() of '\0' ---
91-- after repeating 0 times is =>
92-- after repeating 1 times is => \0
93-- after repeating 2 times is => \0\0
94-- after repeating 3 times is => \0\0\0
95
96--- str_repeat() of '' ---
97-- after repeating 0 times is =>
98-- after repeating 1 times is =>
99-- after repeating 2 times is =>
100-- after repeating 3 times is =>
101
102--- str_repeat() of '1' ---
103-- after repeating 0 times is =>
104-- after repeating 1 times is => 1
105-- after repeating 2 times is => 11
106-- after repeating 3 times is => 111
107
108--- str_repeat() of '4' ---
109-- after repeating 0 times is =>
110-- after repeating 1 times is => 4
111-- after repeating 2 times is => 44
112-- after repeating 3 times is => 444
113
114--- str_repeat() of '1.23' ---
115-- after repeating 0 times is =>
116-- after repeating 1 times is => 1.23
117-- after repeating 2 times is => 1.231.23
118-- after repeating 3 times is => 1.231.231.23
119
120--- str_repeat() of '' ---
121-- after repeating 0 times is =>
122-- after repeating 1 times is =>
123-- after repeating 2 times is =>
124-- after repeating 3 times is =>
125
126--- str_repeat() of ' ' ---
127-- after repeating 0 times is =>
128-- after repeating 1 times is =>
129-- after repeating 2 times is =>
130-- after repeating 3 times is =>
131
132
133*** Testing str_repeat() with various strings & multiplier value ***
134--- str_repeat() of 'a' ---
135-- after repeating 'a' times is =>
136Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
137NULL
138-- after repeating 'foo' times is =>
139Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
140NULL
141-- after repeating 'barbazbax' times is =>
142Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
143NULL
144-- after repeating '�' times is =>
145Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
146NULL
147-- after repeating '\0' times is =>
148Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
149NULL
150-- after repeating '' times is => string(0) ""
151-- after repeating '1' times is => string(1) "a"
152-- after repeating '4' times is => string(4) "aaaa"
153-- after repeating '1.23' times is => string(1) "a"
154-- after repeating '' times is =>
155Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
156NULL
157-- after repeating ' ' times is =>
158Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
159NULL
160
161--- str_repeat() of 'foo' ---
162-- after repeating 'a' times is =>
163Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
164NULL
165-- after repeating 'foo' times is =>
166Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
167NULL
168-- after repeating 'barbazbax' times is =>
169Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
170NULL
171-- after repeating '�' times is =>
172Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
173NULL
174-- after repeating '\0' times is =>
175Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
176NULL
177-- after repeating '' times is => string(0) ""
178-- after repeating '1' times is => string(3) "foo"
179-- after repeating '4' times is => string(12) "foofoofoofoo"
180-- after repeating '1.23' times is => string(3) "foo"
181-- after repeating '' times is =>
182Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
183NULL
184-- after repeating ' ' times is =>
185Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
186NULL
187
188--- str_repeat() of 'barbazbax' ---
189-- after repeating 'a' times is =>
190Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
191NULL
192-- after repeating 'foo' times is =>
193Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
194NULL
195-- after repeating 'barbazbax' times is =>
196Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
197NULL
198-- after repeating '�' times is =>
199Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
200NULL
201-- after repeating '\0' times is =>
202Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
203NULL
204-- after repeating '' times is => string(0) ""
205-- after repeating '1' times is => string(9) "barbazbax"
206-- after repeating '4' times is => string(36) "barbazbaxbarbazbaxbarbazbaxbarbazbax"
207-- after repeating '1.23' times is => string(9) "barbazbax"
208-- after repeating '' times is =>
209Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
210NULL
211-- after repeating ' ' times is =>
212Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
213NULL
214
215--- str_repeat() of '�' ---
216-- after repeating 'a' times is =>
217Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
218NULL
219-- after repeating 'foo' times is =>
220Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
221NULL
222-- after repeating 'barbazbax' times is =>
223Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
224NULL
225-- after repeating '�' times is =>
226Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
227NULL
228-- after repeating '\0' times is =>
229Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
230NULL
231-- after repeating '' times is => string(0) ""
232-- after repeating '1' times is => string(1) "�"
233-- after repeating '4' times is => string(4) "����"
234-- after repeating '1.23' times is => string(1) "�"
235-- after repeating '' times is =>
236Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
237NULL
238-- after repeating ' ' times is =>
239Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
240NULL
241
242--- str_repeat() of '\0' ---
243-- after repeating 'a' times is =>
244Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
245NULL
246-- after repeating 'foo' times is =>
247Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
248NULL
249-- after repeating 'barbazbax' times is =>
250Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
251NULL
252-- after repeating '�' times is =>
253Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
254NULL
255-- after repeating '\0' times is =>
256Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
257NULL
258-- after repeating '' times is => string(0) ""
259-- after repeating '1' times is => string(2) "\0"
260-- after repeating '4' times is => string(8) "\0\0\0\0"
261-- after repeating '1.23' times is => string(2) "\0"
262-- after repeating '' times is =>
263Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
264NULL
265-- after repeating ' ' times is =>
266Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
267NULL
268
269--- str_repeat() of '' ---
270-- after repeating 'a' times is =>
271Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
272NULL
273-- after repeating 'foo' times is =>
274Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
275NULL
276-- after repeating 'barbazbax' times is =>
277Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
278NULL
279-- after repeating '�' times is =>
280Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
281NULL
282-- after repeating '\0' times is =>
283Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
284NULL
285-- after repeating '' times is => string(0) ""
286-- after repeating '1' times is => string(0) ""
287-- after repeating '4' times is => string(0) ""
288-- after repeating '1.23' times is => string(0) ""
289-- after repeating '' times is =>
290Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
291NULL
292-- after repeating ' ' times is =>
293Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
294NULL
295
296--- str_repeat() of '1' ---
297-- after repeating 'a' times is =>
298Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
299NULL
300-- after repeating 'foo' times is =>
301Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
302NULL
303-- after repeating 'barbazbax' times is =>
304Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
305NULL
306-- after repeating '�' times is =>
307Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
308NULL
309-- after repeating '\0' times is =>
310Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
311NULL
312-- after repeating '' times is => string(0) ""
313-- after repeating '1' times is => string(1) "1"
314-- after repeating '4' times is => string(4) "1111"
315-- after repeating '1.23' times is => string(1) "1"
316-- after repeating '' times is =>
317Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
318NULL
319-- after repeating ' ' times is =>
320Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
321NULL
322
323--- str_repeat() of '4' ---
324-- after repeating 'a' times is =>
325Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
326NULL
327-- after repeating 'foo' times is =>
328Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
329NULL
330-- after repeating 'barbazbax' times is =>
331Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
332NULL
333-- after repeating '�' times is =>
334Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
335NULL
336-- after repeating '\0' times is =>
337Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
338NULL
339-- after repeating '' times is => string(0) ""
340-- after repeating '1' times is => string(1) "4"
341-- after repeating '4' times is => string(4) "4444"
342-- after repeating '1.23' times is => string(1) "4"
343-- after repeating '' times is =>
344Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
345NULL
346-- after repeating ' ' times is =>
347Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
348NULL
349
350--- str_repeat() of '1.23' ---
351-- after repeating 'a' times is =>
352Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
353NULL
354-- after repeating 'foo' times is =>
355Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
356NULL
357-- after repeating 'barbazbax' times is =>
358Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
359NULL
360-- after repeating '�' times is =>
361Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
362NULL
363-- after repeating '\0' times is =>
364Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
365NULL
366-- after repeating '' times is => string(0) ""
367-- after repeating '1' times is => string(4) "1.23"
368-- after repeating '4' times is => string(16) "1.231.231.231.23"
369-- after repeating '1.23' times is => string(4) "1.23"
370-- after repeating '' times is =>
371Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
372NULL
373-- after repeating ' ' times is =>
374Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
375NULL
376
377--- str_repeat() of '' ---
378-- after repeating 'a' times is =>
379Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
380NULL
381-- after repeating 'foo' times is =>
382Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
383NULL
384-- after repeating 'barbazbax' times is =>
385Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
386NULL
387-- after repeating '�' times is =>
388Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
389NULL
390-- after repeating '\0' times is =>
391Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
392NULL
393-- after repeating '' times is => string(0) ""
394-- after repeating '1' times is => string(0) ""
395-- after repeating '4' times is => string(0) ""
396-- after repeating '1.23' times is => string(0) ""
397-- after repeating '' times is =>
398Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
399NULL
400-- after repeating ' ' times is =>
401Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
402NULL
403
404--- str_repeat() of ' ' ---
405-- after repeating 'a' times is =>
406Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
407NULL
408-- after repeating 'foo' times is =>
409Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
410NULL
411-- after repeating 'barbazbax' times is =>
412Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
413NULL
414-- after repeating '�' times is =>
415Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
416NULL
417-- after repeating '\0' times is =>
418Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
419NULL
420-- after repeating '' times is => string(0) ""
421-- after repeating '1' times is => string(1) " "
422-- after repeating '4' times is => string(4) "    "
423-- after repeating '1.23' times is => string(1) " "
424-- after repeating '' times is =>
425Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
426NULL
427-- after repeating ' ' times is =>
428Warning: str_repeat() expects parameter 2 to be integer, string given in %s on line %d
429NULL
430
431*** Testing str_repeat() with complex strings containing
432       other than 7-bit chars ***
433string(21) "���������������������"
434string(21) "���������������������"
435
436
437*** Testing error conditions ***
438Warning: str_repeat() expects exactly 2 parameters, 0 given in %s on line %d
439NULL
440
441Warning: str_repeat() expects exactly 2 parameters, 1 given in %s on line %d
442NULL
443
444Warning: str_repeat() expects exactly 2 parameters, 3 given in %s on line %d
445NULL
446
447Warning: str_repeat(): Second argument has to be greater than or equal to 0 in %s on line %d
448NULL
449Done
450