Annotation of embedaddon/php/ext/mbstring/tests/mb_ereg_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mb_ereg() function : usage variations - pass different data types to $string arg
3: --SKIPIF--
4: <?php
5: extension_loaded('mbstring') or die('skip');
6: function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
7: ?>
8: --FILE--
9: <?php
10: /* Prototype : int mb_ereg(string $pattern, string $string [, array $registers])
11: * Description: Regular expression match for multibyte string
12: * Source code: ext/mbstring/php_mbregex.c
13: */
14:
15: /*
16: * Test behaviour of mb_ereg() when passed different data types as $string arg
17: */
18:
19: echo "*** Testing mb_ereg() : usage variations ***\n";
20:
21: // Initialise function arguments not being substituted
22: $pattern = 'str';
23:
24: //get an unset variable
25: $unset_var = 10;
26: unset ($unset_var);
27:
28: // get a class
29: class classA
30: {
31: public function __toString() {
32: return "Class A object";
33: }
34: }
35:
36: // heredoc string
37: $heredoc = <<<EOT
38: hello world
39: EOT;
40:
41: // get a resource variable
42: $fp = fopen(__FILE__, "r");
43:
44: // unexpected values to be passed to $string argument
45: $inputs = array(
46:
47: // int data
48: /*1*/ 0,
49: 1,
50: 12345,
51: -2345,
52:
53: // float data
54: /*5*/ 10.5,
55: -10.5,
56: 12.3456789000e10,
57: 12.3456789000E-10,
58: .5,
59:
60: // null data
61: /*10*/ NULL,
62: null,
63:
64: // boolean data
65: /*12*/ true,
66: false,
67: TRUE,
68: FALSE,
69:
70: // empty data
71: /*16*/ "",
72: '',
73:
74: // string data
75: /*18*/ "string",
76: 'string',
77: $heredoc,
78:
79: // object data
80: /*21*/ new classA(),
81:
82: // undefined data
83: /*22*/ @$undefined_var,
84:
85: // unset data
86: /*23*/ @$unset_var,
87:
88: // resource variable
89: /*24*/ $fp
90: );
91:
92: // loop through each element of $inputs to check the behavior of mb_ereg()
93: $iterator = 1;
94: foreach($inputs as $input) {
95: if (@is_array($regs)){
96: $regs = null;
97: }
98: echo "\n-- Iteration $iterator --\n";
99: var_dump( mb_ereg($pattern, $input, $regs) );
100: var_dump($regs);
101: $iterator++;
102: };
103:
104: fclose($fp);
105:
106: echo "Done";
107:
108: ?>
109:
110: --EXPECTF--
111: *** Testing mb_ereg() : usage variations ***
112:
113: -- Iteration 1 --
114: bool(false)
115: NULL
116:
117: -- Iteration 2 --
118: bool(false)
119: NULL
120:
121: -- Iteration 3 --
122: bool(false)
123: NULL
124:
125: -- Iteration 4 --
126: bool(false)
127: NULL
128:
129: -- Iteration 5 --
130: bool(false)
131: NULL
132:
133: -- Iteration 6 --
134: bool(false)
135: NULL
136:
137: -- Iteration 7 --
138: bool(false)
139: NULL
140:
141: -- Iteration 8 --
142: bool(false)
143: NULL
144:
145: -- Iteration 9 --
146: bool(false)
147: NULL
148:
149: -- Iteration 10 --
150: bool(false)
151: NULL
152:
153: -- Iteration 11 --
154: bool(false)
155: NULL
156:
157: -- Iteration 12 --
158: bool(false)
159: NULL
160:
161: -- Iteration 13 --
162: bool(false)
163: NULL
164:
165: -- Iteration 14 --
166: bool(false)
167: NULL
168:
169: -- Iteration 15 --
170: bool(false)
171: NULL
172:
173: -- Iteration 16 --
174: bool(false)
175: NULL
176:
177: -- Iteration 17 --
178: bool(false)
179: NULL
180:
181: -- Iteration 18 --
182: int(3)
183: array(1) {
184: [0]=>
185: string(3) "str"
186: }
187:
188: -- Iteration 19 --
189: int(3)
190: array(1) {
191: [0]=>
192: string(3) "str"
193: }
194:
195: -- Iteration 20 --
196: bool(false)
197: NULL
198:
199: -- Iteration 21 --
200: bool(false)
201: NULL
202:
203: -- Iteration 22 --
204: bool(false)
205: NULL
206:
207: -- Iteration 23 --
208: bool(false)
209: NULL
210:
211: -- Iteration 24 --
212:
213: Warning: mb_ereg() expects parameter 2 to be string, resource given in %s on line %d
214: bool(false)
215: NULL
216: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>