1--TEST--
2Test mb_ereg_replace() function : usage variations
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_ereg_replace') or die("skip mb_ereg_replace() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : proto string mb_ereg_replace(string pattern, string replacement, string string [, string option])
11 * Description: Replace regular expression for multibyte string
12 * Source code: ext/mbstring/php_mbregex.c
13 * Alias to functions:
14 */
15
16echo "*** Testing mb_ereg_replace() : usage variations ***\n";
17
18// Initialise function arguments not being substituted (if any)
19$pattern = '[a-k]';
20$replacement = '1';
21$string = 'string_val';
22
23//get an unset variable
24$unset_var = 10;
25unset ($unset_var);
26
27// get a class
28class classA
29{
30  public function __toString() {
31    return "UTF-8";
32  }
33}
34
35// heredoc string
36$heredoc = <<<EOT
37UTF-8
38EOT;
39
40// get a resource variable
41$fp = fopen(__FILE__, "r");
42
43// unexpected values to be passed to $encoding argument
44$inputs = array(
45
46       // int data
47/*1*/  0,
48       1,
49       12345,
50       -2345,
51
52       // float data
53/*5*/  10.5,
54       -10.5,
55       12.3456789000e10,
56       12.3456789000E-10,
57       .5,
58
59       // null data
60/*10*/ NULL,
61       null,
62
63       // boolean data
64/*12*/ true,
65       false,
66       TRUE,
67       FALSE,
68
69       // empty data
70/*16*/ "",
71       '',
72
73       // string data
74/*18*/ "UTF-8",
75       'UTF-8',
76       $heredoc,
77
78       // object data
79/*21*/ new classA(),
80
81       // undefined data
82/*22*/ @$undefined_var,
83
84       // unset data
85/*23*/ @$unset_var,
86
87       // resource variable
88/*24*/ $fp
89);
90
91// loop through each element of the array for pattern
92
93$iterator = 1;
94foreach($inputs as $input) {
95      echo "\n-- Iteration $iterator --\n";
96      var_dump( mb_ereg_replace($pattern, $replacement, $string, $input) );
97      $iterator++;
98};
99
100fclose($fp);
101echo "Done";
102?>
103--EXPECTF--
104*** Testing mb_ereg_replace() : usage variations ***
105
106-- Iteration 1 --
107string(10) "str1n1_v1l"
108
109-- Iteration 2 --
110string(10) "str1n1_v1l"
111
112-- Iteration 3 --
113string(10) "str1n1_v1l"
114
115-- Iteration 4 --
116string(10) "str1n1_v1l"
117
118-- Iteration 5 --
119string(10) "str1n1_v1l"
120
121-- Iteration 6 --
122string(10) "str1n1_v1l"
123
124-- Iteration 7 --
125string(10) "str1n1_v1l"
126
127-- Iteration 8 --
128string(10) "str1n1_v1l"
129
130-- Iteration 9 --
131string(10) "str1n1_v1l"
132
133-- Iteration 10 --
134string(10) "str1n1_v1l"
135
136-- Iteration 11 --
137string(10) "str1n1_v1l"
138
139-- Iteration 12 --
140string(10) "str1n1_v1l"
141
142-- Iteration 13 --
143string(10) "str1n1_v1l"
144
145-- Iteration 14 --
146string(10) "str1n1_v1l"
147
148-- Iteration 15 --
149string(10) "str1n1_v1l"
150
151-- Iteration 16 --
152string(10) "str1n1_v1l"
153
154-- Iteration 17 --
155string(10) "str1n1_v1l"
156
157-- Iteration 18 --
158string(10) "str1n1_v1l"
159
160-- Iteration 19 --
161string(10) "str1n1_v1l"
162
163-- Iteration 20 --
164string(10) "str1n1_v1l"
165
166-- Iteration 21 --
167string(10) "str1n1_v1l"
168
169-- Iteration 22 --
170string(10) "str1n1_v1l"
171
172-- Iteration 23 --
173string(10) "str1n1_v1l"
174
175-- Iteration 24 --
176
177Warning: mb_ereg_replace() expects parameter 4 to be string, resource given in %s on line %d
178bool(false)
179Done
180