File: substr_count_error.phpt

package info (click to toggle)
php5 5.6.33%2Bdfsg-0%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 157,872 kB
  • sloc: ansic: 756,065; php: 22,030; sh: 12,311; cpp: 8,771; xml: 6,179; yacc: 1,564; exp: 1,514; makefile: 1,467; pascal: 1,147; awk: 538; perl: 315; sql: 22
file content (65 lines) | stat: -rw-r--r-- 1,698 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
--TEST--
Test substr_count() function (error conditions)
--FILE--
<?php

echo "\n*** Testing error conditions ***\n";
/* Zero argument */
var_dump( substr_count() );

/* more than expected no. of args */
var_dump( substr_count($str, "t", 0, 15, 30) );
	
/* offset as negative value */
var_dump(substr_count($str, "t", -5));

/* offset > size of the string */
var_dump(substr_count($str, "t", 25));

/* Using offset and length to go beyond the size of the string: 
   Warning message expected, as length+offset > length of string */
var_dump( substr_count($str, "i", 5, 15) );

/* length as Null */
var_dump( substr_count($str, "t", "", "") );
var_dump( substr_count($str, "i", NULL, NULL) );
	
echo "Done\n";	

?>
--EXPECTF--
*** Testing error conditions ***

Warning: substr_count() expects at least 2 parameters, 0 given in %s on line %d
NULL

Notice: Undefined variable: str in %s on line %d

Warning: substr_count() expects at most 4 parameters, 5 given in %s on line %d
NULL

Notice: Undefined variable: str in %s on line %d

Warning: substr_count(): Offset should be greater than or equal to 0 in %s on line %d
bool(false)

Notice: Undefined variable: str in %s on line %d

Warning: substr_count(): Offset value 25 exceeds string length in %s on line %d
bool(false)

Notice: Undefined variable: str in %s on line %d

Warning: substr_count(): Offset value 5 exceeds string length in %s on line %d
bool(false)

Notice: Undefined variable: str in %s on line %d

Warning: substr_count() expects parameter 3 to be long, string given in %s on line %d
NULL

Notice: Undefined variable: str in %s on line %d

Warning: substr_count(): Length should be greater than 0 in %s on line %d
bool(false)
Done