1--TEST--
2Test strspn() function : usage variations - unexpected values for mask argument
3--FILE--
4<?php
5/* Prototype  : proto int strspn(string str, string mask [, int start [, int len]])
6 * Description: Finds length of initial segment consisting entirely of characters found in mask.
7		If start or/and length is provided works like strspn(substr($s,$start,$len),$good_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 strspn() : with different unexpected values for mask argument
16*/
17
18echo "*** Testing strspn() : 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( strspn($str,$value) );  // with defalut args
95      var_dump( strspn($str,$value,$start) );  // with default len value
96      var_dump( strspn($str,$value,$start,$len) );  // with all args
97};
98
99// close the resource
100fclose($file_handle);
101
102echo "Done"
103?>
104--EXPECTF--
105*** Testing strspn() : with different unexpected values of mask argument ***
106
107-- Iteration with mask value as "0" --
108int(0)
109int(0)
110int(0)
111
112-- Iteration with mask value as "1" --
113int(0)
114int(0)
115int(0)
116
117-- Iteration with mask value as "12345" --
118int(0)
119int(0)
120int(0)
121
122-- Iteration with mask value as "-2345" --
123int(0)
124int(0)
125int(0)
126
127-- Iteration with mask value as "10.5" --
128int(0)
129int(0)
130int(0)
131
132-- Iteration with mask value as "-10.5" --
133int(0)
134int(0)
135int(0)
136
137-- Iteration with mask value as "101234567000" --
138int(0)
139int(0)
140int(0)
141
142-- Iteration with mask value as "1.07654321E-9" --
143int(0)
144int(0)
145int(0)
146
147-- Iteration with mask value as "0.5" --
148int(0)
149int(0)
150int(0)
151
152-- Iteration with mask value as "Array" --
153
154Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
155NULL
156
157Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
158NULL
159
160Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
161NULL
162
163-- Iteration with mask value as "Array" --
164
165Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
166NULL
167
168Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
169NULL
170
171Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
172NULL
173
174-- Iteration with mask value as "Array" --
175
176Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
177NULL
178
179Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
180NULL
181
182Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
183NULL
184
185-- Iteration with mask value as "Array" --
186
187Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
188NULL
189
190Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
191NULL
192
193Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
194NULL
195
196-- Iteration with mask value as "Array" --
197
198Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
199NULL
200
201Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
202NULL
203
204Warning: strspn() expects parameter 2 to be string, array given in %s on line %d
205NULL
206
207-- Iteration with mask value as "" --
208int(0)
209int(0)
210int(0)
211
212-- Iteration with mask value as "" --
213int(0)
214int(0)
215int(0)
216
217-- Iteration with mask value as "1" --
218int(0)
219int(0)
220int(0)
221
222-- Iteration with mask value as "" --
223int(0)
224int(0)
225int(0)
226
227-- Iteration with mask value as "1" --
228int(0)
229int(0)
230int(0)
231
232-- Iteration with mask value as "" --
233int(0)
234int(0)
235int(0)
236
237-- Iteration with mask value as "" --
238int(0)
239int(0)
240int(0)
241
242-- Iteration with mask value as "" --
243int(0)
244int(0)
245int(0)
246
247-- Iteration with mask value as "object" --
248int(0)
249int(1)
250int(1)
251
252-- Iteration with mask value as "" --
253int(0)
254int(0)
255int(0)
256
257-- Iteration with mask value as "" --
258int(0)
259int(0)
260int(0)
261
262-- Iteration with mask value as "Resource id #%d" --
263
264Warning: strspn() expects parameter 2 to be string, resource given in %s on line %d
265NULL
266
267Warning: strspn() expects parameter 2 to be string, resource given in %s on line %d
268NULL
269
270Warning: strspn() expects parameter 2 to be string, resource given in %s on line %d
271NULL
272Done