1--TEST--
2Test strcspn() function : usage variations - unexpected values of start 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 unexpected values of start argument
16*/
17
18echo "*** Testing strcspn() : with unexpected values of start argument ***\n";
19
20// initialing required variables
21$str = 'string_val';
22$mask = 'soibtFTf1234567890';
23$len = 10;
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      // float data
44      10.5,
45      -10.5,
46      10.1234567e8,
47      10.7654321E-8,
48      .5,
49
50      // array data
51      array(),
52      array(0),
53      array(1),
54      array(1, 2),
55      array('color' => 'red', 'item' => 'pen'),
56
57      // null data
58      NULL,
59      null,
60
61      // boolean data
62      true,
63      false,
64      TRUE,
65      FALSE,
66
67      // empty data
68      "",
69      '',
70
71      // string data
72      "string",
73      'string',
74
75      // object data
76      new sample(),
77
78      // undefined data
79      $undefined_var,
80
81      // unset data
82      $unset_var,
83
84      // resource
85      $file_handle
86);
87
88// loop through each element of the array for start
89
90foreach($values as $value) {
91      echo "\n-- Iteration with start value as \"$value\" --\n";
92      var_dump( strcspn($str,$mask,$value) );  // with default len value
93      var_dump( strcspn($str,$mask,$value,$len) );  // with all args
94};
95
96// closing the resource
97fclose($file_handle);
98
99echo "Done"
100?>
101--EXPECTF--
102*** Testing strcspn() : with unexpected values of start argument ***
103
104-- Iteration with start value as "10.5" --
105int(0)
106int(0)
107
108-- Iteration with start value as "-10.5" --
109int(0)
110int(0)
111
112-- Iteration with start value as "1012345670" --
113bool(false)
114bool(false)
115
116-- Iteration with start value as "1.07654321E-7" --
117int(0)
118int(0)
119
120-- Iteration with start value as "0.5" --
121int(0)
122int(0)
123
124-- Iteration with start value as "Array" --
125
126Warning: strcspn() expects parameter 3 to be integer, array given in %s on line %d
127NULL
128
129Warning: strcspn() expects parameter 3 to be integer, array given in %s on line %d
130NULL
131
132-- Iteration with start value as "Array" --
133
134Warning: strcspn() expects parameter 3 to be integer, array given in %s on line %d
135NULL
136
137Warning: strcspn() expects parameter 3 to be integer, array given in %s on line %d
138NULL
139
140-- Iteration with start value as "Array" --
141
142Warning: strcspn() expects parameter 3 to be integer, array given in %s on line %d
143NULL
144
145Warning: strcspn() expects parameter 3 to be integer, array given in %s on line %d
146NULL
147
148-- Iteration with start value as "Array" --
149
150Warning: strcspn() expects parameter 3 to be integer, array given in %s on line %d
151NULL
152
153Warning: strcspn() expects parameter 3 to be integer, array given in %s on line %d
154NULL
155
156-- Iteration with start value as "Array" --
157
158Warning: strcspn() expects parameter 3 to be integer, array given in %s on line %d
159NULL
160
161Warning: strcspn() expects parameter 3 to be integer, array given in %s on line %d
162NULL
163
164-- Iteration with start value as "" --
165int(0)
166int(0)
167
168-- Iteration with start value as "" --
169int(0)
170int(0)
171
172-- Iteration with start value as "1" --
173int(0)
174int(0)
175
176-- Iteration with start value as "" --
177int(0)
178int(0)
179
180-- Iteration with start value as "1" --
181int(0)
182int(0)
183
184-- Iteration with start value as "" --
185int(0)
186int(0)
187
188-- Iteration with start value as "" --
189
190Warning: strcspn() expects parameter 3 to be integer, string given in %s on line %d
191NULL
192
193Warning: strcspn() expects parameter 3 to be integer, string given in %s on line %d
194NULL
195
196-- Iteration with start value as "" --
197
198Warning: strcspn() expects parameter 3 to be integer, string given in %s on line %d
199NULL
200
201Warning: strcspn() expects parameter 3 to be integer, string given in %s on line %d
202NULL
203
204-- Iteration with start value as "string" --
205
206Warning: strcspn() expects parameter 3 to be integer, string given in %s on line %d
207NULL
208
209Warning: strcspn() expects parameter 3 to be integer, string given in %s on line %d
210NULL
211
212-- Iteration with start value as "string" --
213
214Warning: strcspn() expects parameter 3 to be integer, string given in %s on line %d
215NULL
216
217Warning: strcspn() expects parameter 3 to be integer, string given in %s on line %d
218NULL
219
220-- Iteration with start value as "object" --
221
222Warning: strcspn() expects parameter 3 to be integer, object given in %s on line %d
223NULL
224
225Warning: strcspn() expects parameter 3 to be integer, object given in %s on line %d
226NULL
227
228-- Iteration with start value as "" --
229int(0)
230int(0)
231
232-- Iteration with start value as "" --
233int(0)
234int(0)
235
236-- Iteration with start value as "Resource id #%d" --
237
238Warning: strcspn() expects parameter 3 to be integer, resource given in %s on line %d
239NULL
240
241Warning: strcspn() expects parameter 3 to be integer, resource given in %s on line %d
242NULL
243Done
244