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