Annotation of embedaddon/php/ext/standard/tests/strings/stristr_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test stristr() function : usage variations - test values for $needle argument
3: --FILE--
4: <?php
5:
6: /* Prototype: string stristr ( string $haystack, string $needle );
7: Description: Case-insensitive strstr().
8: */
9:
10: echo "*** Testing stristr() function: with unexpected inputs for 'needle' argument ***\n";
11:
12: //get an unset variable
13: $unset_var = 'string_val';
14: unset($unset_var);
15:
16: //defining a class
17: class sample {
18: public function __toString() {
19: return "sample object";
20: }
21: }
22:
23: //getting the resource
24: $file_handle = fopen(__FILE__, "r");
25:
26: // array with different values for $input
27: $inputs = array (
28:
29: // integer values
30: /*1*/ 0,
31: 1,
32: -2,
33: -PHP_INT_MAX,
34:
35: // float values
36: /*5*/ 10.5,
37: -20.5,
38: 10.1234567e10,
39:
40: // array values
41: /*8*/ array(),
42: array(0),
43: array(1, 2),
44:
45: // boolean values
46: /*11*/ true,
47: false,
48: TRUE,
49: FALSE,
50:
51: // null vlaues
52: /*15*/ NULL,
53: null,
54:
55: // objects
56: /*17*/ new sample(),
57:
58: // resource
59: /*18*/ $file_handle,
60:
61: // undefined variable
62: /*19*/ @$undefined_var,
63:
64: // unset variable
65: /*20*/ @$unset_var
66: );
67:
68: //defining '$pad_length' argument
69: $pad_length = "20";
70:
71: // loop through with each element of the $inputs array to test stristr() function
72: $count = 1;
73: foreach($inputs as $input) {
74: echo "-- Iteration $count --\n";
75: var_dump( stristr("Hello World", $input) );
76: $count ++;
77: }
78:
79: fclose($file_handle); //closing the file handle
80:
81: ?>
82: ===DONE===
83: --EXPECTF--
84: *** Testing stristr() function: with unexpected inputs for 'needle' argument ***
85: -- Iteration 1 --
86: bool(false)
87: -- Iteration 2 --
88: bool(false)
89: -- Iteration 3 --
90: bool(false)
91: -- Iteration 4 --
92: bool(false)
93: -- Iteration 5 --
94: bool(false)
95: -- Iteration 6 --
96: bool(false)
97: -- Iteration 7 --
98: bool(false)
99: -- Iteration 8 --
100:
101: Warning: stristr(): needle is not a string or an integer in %s on line %d
102: bool(false)
103: -- Iteration 9 --
104:
105: Warning: stristr(): needle is not a string or an integer in %s on line %d
106: bool(false)
107: -- Iteration 10 --
108:
109: Warning: stristr(): needle is not a string or an integer in %s on line %d
110: bool(false)
111: -- Iteration 11 --
112: bool(false)
113: -- Iteration 12 --
114: bool(false)
115: -- Iteration 13 --
116: bool(false)
117: -- Iteration 14 --
118: bool(false)
119: -- Iteration 15 --
120: bool(false)
121: -- Iteration 16 --
122: bool(false)
123: -- Iteration 17 --
124:
125: Notice: Object of class sample could not be converted to int in %s on line %d
126: bool(false)
127: -- Iteration 18 --
128:
129: Warning: stristr(): needle is not a string or an integer in %s on line %d
130: bool(false)
131: -- Iteration 19 --
132: bool(false)
133: -- Iteration 20 --
134: bool(false)
135: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>