Annotation of embedaddon/php/ext/standard/tests/strings/strspn_variation4.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test strspn() function : usage variations - unexpected values of len 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:
12: error_reporting(E_ALL & ~E_NOTICE);
13:
14: /*
15: * Testing strspn() : with unexpected values of len argument
16: */
17:
18: echo "*** Testing strspn() : with unexpected values of len argument ***\n";
19:
20: // initialing required variables
21: $str = 'string_val';
22: $mask = 'soibtFTf1234567890';
23: $start = 0;
24:
25: //get an unset variable
26: $unset_var = 10;
27: unset ($unset_var);
28:
29: // declaring class
30: class 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:
90: foreach($values as $value) {
91: echo "\n-- Iteration with len value as \"$value\" --\n";
92: var_dump( strspn($str,$mask,$start,$value) ); // with all args
93: };
94:
95: // closing the resource
96: fclose($file_handle);
97:
98: echo "Done"
99: ?>
100: --EXPECTF--
101: *** Testing strspn() : with unexpected values of len argument ***
102:
103: -- Iteration with len value as "10.5" --
104: int(2)
105:
106: -- Iteration with len value as "-10.5" --
107: int(0)
108:
109: -- Iteration with len value as "1012345670" --
110: int(2)
111:
112: -- Iteration with len value as "1.07654321E-7" --
113: int(0)
114:
115: -- Iteration with len value as "0.5" --
116: int(0)
117:
118: -- Iteration with len value as "Array" --
119:
120: Warning: strspn() expects parameter 4 to be long, array given in %s on line %d
121: NULL
122:
123: -- Iteration with len value as "Array" --
124:
125: Warning: strspn() expects parameter 4 to be long, array given in %s on line %d
126: NULL
127:
128: -- Iteration with len value as "Array" --
129:
130: Warning: strspn() expects parameter 4 to be long, array given in %s on line %d
131: NULL
132:
133: -- Iteration with len value as "Array" --
134:
135: Warning: strspn() expects parameter 4 to be long, array given in %s on line %d
136: NULL
137:
138: -- Iteration with len value as "Array" --
139:
140: Warning: strspn() expects parameter 4 to be long, array given in %s on line %d
141: NULL
142:
143: -- Iteration with len value as "" --
144: int(0)
145:
146: -- Iteration with len value as "" --
147: int(0)
148:
149: -- Iteration with len value as "1" --
150: int(1)
151:
152: -- Iteration with len value as "" --
153: int(0)
154:
155: -- Iteration with len value as "1" --
156: int(1)
157:
158: -- Iteration with len value as "" --
159: int(0)
160:
161: -- Iteration with len value as "" --
162:
163: Warning: strspn() expects parameter 4 to be long, string given in %s on line %d
164: NULL
165:
166: -- Iteration with len value as "" --
167:
168: Warning: strspn() expects parameter 4 to be long, string given in %s on line %d
169: NULL
170:
171: -- Iteration with len value as "string" --
172:
173: Warning: strspn() expects parameter 4 to be long, string given in %s on line %d
174: NULL
175:
176: -- Iteration with len value as "string" --
177:
178: Warning: strspn() expects parameter 4 to be long, string given in %s on line %d
179: NULL
180:
181: -- Iteration with len value as "object" --
182:
183: Warning: strspn() expects parameter 4 to be long, object given in %s on line %d
184: NULL
185:
186: -- Iteration with len value as "" --
187: int(0)
188:
189: -- Iteration with len value as "" --
190: int(0)
191:
192: -- Iteration with len value as "Resource id #%d" --
193:
194: Warning: strspn() expects parameter 4 to be long, resource given in %s on line %d
195: NULL
196: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>