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