1--TEST-- 2Test strncasecmp() function : usage variations - unexpected values for 'str1' & 'str2' 3--FILE-- 4<?php 5/* Prototype : int strncasecmp ( string $str1, string $str2, int $len ); 6 * Description: Binary safe case-insensitive string comparison of the first n characters 7 * Source code: Zend/zend_builtin_functions.c 8*/ 9 10/* Test strncasecmp() function with the unexpected inputs for 'str1' and 'str2' */ 11 12echo "*** Testing strncasecmp() function: with unexpected values for 'str1' and 'str2' ***\n"; 13/* get an unset variable */ 14$unset_var = 'string_val'; 15unset($unset_var); 16 17/* get resource handle */ 18$file_handle = fopen(__FILE__, "r"); 19 20/* declaring a class */ 21class sample { 22 public function __toString() { 23 return "object"; 24 } 25} 26 27 28/* array with different values */ 29$values = array ( 30 /* integer values */ 31 0, 32 1, 33 12345, 34 -2345, 35 36 /* float values */ 37 10.5, 38 -10.5, 39 10.5e10, 40 10.6E-10, 41 .5, 42 43 /* hexadecimal values */ 44 0x12, 45 -0x12, 46 47 /* octal values */ 48 012, 49 -012, 50 01.2, 51 52 /* array values */ 53 array(), 54 array(0), 55 array(1), 56 array(1, 2), 57 array('color' => 'red', 'item' => 'pen'), 58 59 /* boolean values */ 60 true, 61 false, 62 TRUE, 63 FALSE, 64 65 /* nulls */ 66 NULL, 67 null, 68 69 /* empty string */ 70 "", 71 '', 72 73 /* undefined variable */ 74 @$undefined_var, 75 76 /* unset variable */ 77 @$unset_var, 78 79 /* resource */ 80 $file_handle, 81 82 /* object */ 83 new sample() 84); 85 86/* loop through each element of the array and check the working of strncasecmp() */ 87$counter = 1; 88for($index = 0; $index < count($values); $index ++) { 89 echo "-- Iteration $counter --\n"; 90 $str1 = $values[$index]; 91 $str2 = $values[$index]; 92 $len = strlen($values[$index]) + 1; 93 var_dump( strncasecmp($str1, $str2, $len) ); 94 $counter ++; 95} 96 97fclose($file_handle); //closing the file handle 98 99echo "*** Done ***\n"; 100?> 101--EXPECTF-- 102*** Testing strncasecmp() function: with unexpected values for 'str1' and 'str2' *** 103-- Iteration 1 -- 104int(0) 105-- Iteration 2 -- 106int(0) 107-- Iteration 3 -- 108int(0) 109-- Iteration 4 -- 110int(0) 111-- Iteration 5 -- 112int(0) 113-- Iteration 6 -- 114int(0) 115-- Iteration 7 -- 116int(0) 117-- Iteration 8 -- 118int(0) 119-- Iteration 9 -- 120int(0) 121-- Iteration 10 -- 122int(0) 123-- Iteration 11 -- 124int(0) 125-- Iteration 12 -- 126int(0) 127-- Iteration 13 -- 128int(0) 129-- Iteration 14 -- 130int(0) 131-- Iteration 15 -- 132 133Warning: strlen() expects parameter 1 to be string, array given in %s on line %d 134 135Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line %d 136NULL 137-- Iteration 16 -- 138 139Warning: strlen() expects parameter 1 to be string, array given in %s on line %d 140 141Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line %d 142NULL 143-- Iteration 17 -- 144 145Warning: strlen() expects parameter 1 to be string, array given in %s on line %d 146 147Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line %d 148NULL 149-- Iteration 18 -- 150 151Warning: strlen() expects parameter 1 to be string, array given in %s on line %d 152 153Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line %d 154NULL 155-- Iteration 19 -- 156 157Warning: strlen() expects parameter 1 to be string, array given in %s on line %d 158 159Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line %d 160NULL 161-- Iteration 20 -- 162int(0) 163-- Iteration 21 -- 164int(0) 165-- Iteration 22 -- 166int(0) 167-- Iteration 23 -- 168int(0) 169-- Iteration 24 -- 170int(0) 171-- Iteration 25 -- 172int(0) 173-- Iteration 26 -- 174int(0) 175-- Iteration 27 -- 176int(0) 177-- Iteration 28 -- 178int(0) 179-- Iteration 29 -- 180int(0) 181-- Iteration 30 -- 182 183Warning: strlen() expects parameter 1 to be string, resource given in %s on line %d 184 185Warning: strncasecmp() expects parameter 1 to be string, resource given in %s on line %d 186NULL 187-- Iteration 31 -- 188int(0) 189*** Done *** 190