1--TEST--
2Test str_repeat() function
3--INI--
4precision=14
5--FILE--
6<?php
7echo "*** Testing str_repeat() with possible strings ***";
8$variations = array(
9  'a',
10  'foo',
11  'barbazbax',
12  "\x00",
13  '\0',
14  NULL,
15  TRUE,
16  4,
17  1.23,
18  "",
19  " "
20);
21
22/* variations in string and multiplier as an int */
23foreach($variations as $input) {
24  echo "\n--- str_repeat() of '$input' ---\n" ;
25  for($n=0; $n<4; $n++) {
26    echo "-- after repeating $n times is => ";
27    echo str_repeat($input, $n)."\n";
28  }
29}
30
31echo "\n\n*** Testing error conditions ***\n";
32try {
33    str_repeat($input[0], -1); // Invalid arg for multiplier
34} catch (\ValueError $e) {
35    echo $e->getMessage() . "\n";
36}
37
38?>
39
40--EXPECT--
41*** Testing str_repeat() with possible strings ***
42--- str_repeat() of 'a' ---
43-- after repeating 0 times is =>
44-- after repeating 1 times is => a
45-- after repeating 2 times is => aa
46-- after repeating 3 times is => aaa
47
48--- str_repeat() of 'foo' ---
49-- after repeating 0 times is =>
50-- after repeating 1 times is => foo
51-- after repeating 2 times is => foofoo
52-- after repeating 3 times is => foofoofoo
53
54--- str_repeat() of 'barbazbax' ---
55-- after repeating 0 times is =>
56-- after repeating 1 times is => barbazbax
57-- after repeating 2 times is => barbazbaxbarbazbax
58-- after repeating 3 times is => barbazbaxbarbazbaxbarbazbax
59
60--- str_repeat() of '�' ---
61-- after repeating 0 times is =>
62-- after repeating 1 times is => �
63-- after repeating 2 times is => ��
64-- after repeating 3 times is => ���
65
66--- str_repeat() of '\0' ---
67-- after repeating 0 times is =>
68-- after repeating 1 times is => \0
69-- after repeating 2 times is => \0\0
70-- after repeating 3 times is => \0\0\0
71
72--- str_repeat() of '' ---
73-- after repeating 0 times is =>
74-- after repeating 1 times is =>
75-- after repeating 2 times is =>
76-- after repeating 3 times is =>
77
78--- str_repeat() of '1' ---
79-- after repeating 0 times is =>
80-- after repeating 1 times is => 1
81-- after repeating 2 times is => 11
82-- after repeating 3 times is => 111
83
84--- str_repeat() of '4' ---
85-- after repeating 0 times is =>
86-- after repeating 1 times is => 4
87-- after repeating 2 times is => 44
88-- after repeating 3 times is => 444
89
90--- str_repeat() of '1.23' ---
91-- after repeating 0 times is =>
92-- after repeating 1 times is => 1.23
93-- after repeating 2 times is => 1.231.23
94-- after repeating 3 times is => 1.231.231.23
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 ' ' ---
103-- after repeating 0 times is =>
104-- after repeating 1 times is =>
105-- after repeating 2 times is =>
106-- after repeating 3 times is =>
107
108
109*** Testing error conditions ***
110str_repeat(): Argument #2 ($times) must be greater than or equal to 0
111