1--TEST--
2Test stristr() function : usage variations - test values for $haystack argument
3--FILE--
4<?php
5
6/* Prototype: string stristr ( string $haystack, string $needle );
7   Description: Case-insensitive strstr().
8*/
9
10echo "*** Testing stristr() function: with unexpected inputs for 'string' argument ***\n";
11
12//get an unset variable
13$unset_var = 'string_val';
14unset($unset_var);
15
16//defining a class
17class 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 values
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;
73foreach($inputs as $input) {
74  echo "-- Iteration $count --\n";
75  var_dump( stristr($input, " ") );
76  $count ++;
77}
78
79fclose($file_handle);  //closing the file handle
80
81?>
82===DONE===
83--EXPECTF--
84*** Testing stristr() function: with unexpected inputs for 'string' argument ***
85-- Iteration 1 --
86bool(false)
87-- Iteration 2 --
88bool(false)
89-- Iteration 3 --
90bool(false)
91-- Iteration 4 --
92bool(false)
93-- Iteration 5 --
94bool(false)
95-- Iteration 6 --
96bool(false)
97-- Iteration 7 --
98bool(false)
99-- Iteration 8 --
100
101Warning: stristr() expects parameter 1 to be string, array given in %s on line %d2
102NULL
103-- Iteration 9 --
104
105Warning: stristr() expects parameter 1 to be string, array given in %s on line %d2
106NULL
107-- Iteration 10 --
108
109Warning: stristr() expects parameter 1 to be string, array given in %s on line %d2
110NULL
111-- Iteration 11 --
112bool(false)
113-- Iteration 12 --
114bool(false)
115-- Iteration 13 --
116bool(false)
117-- Iteration 14 --
118bool(false)
119-- Iteration 15 --
120bool(false)
121-- Iteration 16 --
122bool(false)
123-- Iteration 17 --
124string(7) " object"
125-- Iteration 18 --
126
127Warning: stristr() expects parameter 1 to be string, resource given in %s on line %d2
128NULL
129-- Iteration 19 --
130bool(false)
131-- Iteration 20 --
132bool(false)
133===DONE===
134