1--TEST--
2Test strcspn() function : usage variations - unexpected values for mask argument
3--FILE--
4<?php
5/* Prototype  : proto int strcspn(string str, string mask [, int start [, int len]])
6 * Description: Finds length of initial segment consisting entirely of characters not found in mask.
7		If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars)
8 * Source code: ext/standard/string.c
9 * Alias to functions: none
10*/
11
12error_reporting(E_ALL & ~E_NOTICE);
13
14/*
15* Testing strcspn() : with different unexpected values for mask argument
16*/
17
18echo "*** Testing strcspn() : with different unexpected values of mask argument ***\n";
19
20$str = 'string_val';
21$start = 1;
22$len = 10;
23
24
25//get an unset variable
26$unset_var = 10;
27unset ($unset_var);
28
29// declaring class
30class sample  {
31  public function __toString() {
32    return "object";
33  }
34}
35
36// creating a file resource
37$file_handle = fopen(__FILE__, 'r');
38
39
40//array of values to iterate over
41$values = array(
42
43      // int data
44      0,
45      1,
46      12345,
47      -2345,
48
49      // float data
50      10.5,
51      -10.5,
52      10.1234567e10,
53      10.7654321E-10,
54      .5,
55
56      // array data
57      array(),
58      array(0),
59      array(1),
60      array(1, 2),
61      array('color' => 'red', 'item' => 'pen'),
62
63      // null data
64      NULL,
65      null,
66
67      // boolean data
68      true,
69      false,
70      TRUE,
71      FALSE,
72
73      // empty data
74      "",
75      '',
76
77      // object data
78      new sample(),
79
80      // undefined data
81      $undefined_var,
82
83      // unset data
84      $unset_var,
85
86      // resource
87      $file_handle
88);
89
90// loop through each element of the array for mask
91
92foreach($values as $value) {
93      echo "\n-- Iteration with mask value as \"$value\" --\n";
94      var_dump( strcspn($str,$value) );  // with defalut args
95      var_dump( strcspn($str,$value,$start) );  // with default len value
96      var_dump( strcspn($str,$value,$start,$len) );  // with all args
97};
98
99// close the resource
100fclose($file_handle);
101
102echo "Done"
103?>
104--EXPECTF--
105*** Testing strcspn() : with different unexpected values of mask argument ***
106
107-- Iteration with mask value as "0" --
108int(10)
109int(9)
110int(9)
111
112-- Iteration with mask value as "1" --
113int(10)
114int(9)
115int(9)
116
117-- Iteration with mask value as "12345" --
118int(10)
119int(9)
120int(9)
121
122-- Iteration with mask value as "-2345" --
123int(10)
124int(9)
125int(9)
126
127-- Iteration with mask value as "10.5" --
128int(10)
129int(9)
130int(9)
131
132-- Iteration with mask value as "-10.5" --
133int(10)
134int(9)
135int(9)
136
137-- Iteration with mask value as "101234567000" --
138int(10)
139int(9)
140int(9)
141
142-- Iteration with mask value as "1.07654321E-9" --
143int(10)
144int(9)
145int(9)
146
147-- Iteration with mask value as "0.5" --
148int(10)
149int(9)
150int(9)
151
152-- Iteration with mask value as "Array" --
153
154Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
155NULL
156
157Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
158NULL
159
160Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
161NULL
162
163-- Iteration with mask value as "Array" --
164
165Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
166NULL
167
168Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
169NULL
170
171Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
172NULL
173
174-- Iteration with mask value as "Array" --
175
176Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
177NULL
178
179Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
180NULL
181
182Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
183NULL
184
185-- Iteration with mask value as "Array" --
186
187Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
188NULL
189
190Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
191NULL
192
193Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
194NULL
195
196-- Iteration with mask value as "Array" --
197
198Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
199NULL
200
201Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
202NULL
203
204Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
205NULL
206
207-- Iteration with mask value as "" --
208int(10)
209int(9)
210int(9)
211
212-- Iteration with mask value as "" --
213int(10)
214int(9)
215int(9)
216
217-- Iteration with mask value as "1" --
218int(10)
219int(9)
220int(9)
221
222-- Iteration with mask value as "" --
223int(10)
224int(9)
225int(9)
226
227-- Iteration with mask value as "1" --
228int(10)
229int(9)
230int(9)
231
232-- Iteration with mask value as "" --
233int(10)
234int(9)
235int(9)
236
237-- Iteration with mask value as "" --
238int(10)
239int(9)
240int(9)
241
242-- Iteration with mask value as "" --
243int(10)
244int(9)
245int(9)
246
247-- Iteration with mask value as "object" --
248int(1)
249int(0)
250int(0)
251
252-- Iteration with mask value as "" --
253int(10)
254int(9)
255int(9)
256
257-- Iteration with mask value as "" --
258int(10)
259int(9)
260int(9)
261
262-- Iteration with mask value as "Resource id #%d" --
263
264Warning: strcspn() expects parameter 2 to be string, resource given in %s on line %d
265NULL
266
267Warning: strcspn() expects parameter 2 to be string, resource given in %s on line %d
268NULL
269
270Warning: strcspn() expects parameter 2 to be string, resource given in %s on line %d
271NULL
272Done
273