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