1--TEST--
2Test stristr() function : usage variations - test values for $needle argument
3--FILE--
4<?php
5
6echo "*** Testing stristr() function: with unexpected inputs for 'needle' argument ***\n";
7
8//defining a class
9class sample  {
10  public function __toString() {
11    return "sample object";
12  }
13}
14
15//getting the resource
16$file_handle = fopen(__FILE__, "r");
17
18// array with different values for $input
19$inputs =  array (
20
21          // integer values
22/*1*/	  0,
23          1,
24          -2,
25          -PHP_INT_MAX,
26
27          // float values
28/*5*/	  10.5,
29          -20.5,
30          10.1234567e10,
31
32          // array values
33/*8*/	  array(),
34          array(0),
35          array(1, 2),
36
37          // boolean values
38/*11*/	  true,
39          false,
40          TRUE,
41          FALSE,
42
43          // objects
44/*17*/	  new sample(),
45
46          // resource
47/*18*/	  $file_handle,
48);
49
50//defining '$pad_length' argument
51$pad_length = "20";
52
53// loop through with each element of the $inputs array to test stristr() function
54$count = 1;
55foreach($inputs as $input) {
56  echo "-- Iteration $count --\n";
57  try {
58    var_dump( stristr("Hello World", $input) );
59  } catch (TypeError $e) {
60    echo $e->getMessage(), "\n";
61  }
62  $count ++;
63}
64
65fclose($file_handle);  //closing the file handle
66
67?>
68--EXPECT--
69*** Testing stristr() function: with unexpected inputs for 'needle' argument ***
70-- Iteration 1 --
71bool(false)
72-- Iteration 2 --
73bool(false)
74-- Iteration 3 --
75bool(false)
76-- Iteration 4 --
77bool(false)
78-- Iteration 5 --
79bool(false)
80-- Iteration 6 --
81bool(false)
82-- Iteration 7 --
83bool(false)
84-- Iteration 8 --
85stristr(): Argument #2 ($needle) must be of type string, array given
86-- Iteration 9 --
87stristr(): Argument #2 ($needle) must be of type string, array given
88-- Iteration 10 --
89stristr(): Argument #2 ($needle) must be of type string, array given
90-- Iteration 11 --
91bool(false)
92-- Iteration 12 --
93string(11) "Hello World"
94-- Iteration 13 --
95bool(false)
96-- Iteration 14 --
97string(11) "Hello World"
98-- Iteration 15 --
99bool(false)
100-- Iteration 16 --
101stristr(): Argument #2 ($needle) must be of type string, resource given
102