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