1--TEST-- 2Test stripslashes() function : usage variations - non-string type argument 3--FILE-- 4<?php 5/* Prototype : string stripslashes ( string $str ) 6 * Description: Returns an un-quoted string 7 * Source code: ext/standard/string.c 8*/ 9 10/* 11 * Test stripslashes() with non-string type argument such as int, float, etc 12*/ 13 14echo "*** Testing stripslashes() : with non-string type argument ***\n"; 15// initialize all required variables 16 17// get an unset variable 18$unset_var = 'string_val'; 19unset($unset_var); 20 21// declaring a class 22class sample { 23 public function __toString() { 24 return "obj\'ct"; 25 } 26} 27 28// Defining resource 29$file_handle = fopen(__FILE__, 'r'); 30 31// array with different values 32$values = array ( 33 34 // integer values 35/*1*/ 0, 36 1, 37 12345, 38 -2345, 39 40 // float values 41/*5*/ 10.5, 42 -10.5, 43 10.1234567e10, 44 10.7654321E-10, 45 .5, 46 47 // array values 48/*10*/ array(), 49 array(0), 50 array(1), 51 array(1, 2), 52 array('color' => 'red', 'item' => 'pen'), 53 54 // boolean values 55/*15*/ true, 56 false, 57 TRUE, 58 FALSE, 59 60 // empty string 61/*19*/ "", 62 '', 63 64 // undefined variable 65/*21*/ $undefined_var, 66 67 // unset variable 68/*22*/ $unset_var, 69 70 // objects 71/*23*/ new sample(), 72 73 // resource 74/*24*/ $file_handle, 75 76 // null values 77/*25*/ NULL, 78 null 79); 80 81 82// loop through each element of the array and check the working of stripslashes() 83// when $str argument is supplied with different values 84echo "\n--- Testing stripslashes() by supplying different values for 'str' argument ---\n"; 85$counter = 1; 86for($index = 0; $index < count($values); $index ++) { 87 echo "-- Iteration $counter --\n"; 88 $str = $values [$index]; 89 90 var_dump( stripslashes($str) ); 91 92 $counter ++; 93} 94 95// closing the file 96fclose($file_handle); 97 98?> 99===DONE=== 100--EXPECTF-- 101*** Testing stripslashes() : with non-string type argument *** 102 103Notice: Undefined variable: undefined_var in %s on line %d 104 105Notice: Undefined variable: unset_var in %s on line %d 106 107--- Testing stripslashes() by supplying different values for 'str' argument --- 108-- Iteration 1 -- 109string(1) "0" 110-- Iteration 2 -- 111string(1) "1" 112-- Iteration 3 -- 113string(5) "12345" 114-- Iteration 4 -- 115string(5) "-2345" 116-- Iteration 5 -- 117string(4) "10.5" 118-- Iteration 6 -- 119string(5) "-10.5" 120-- Iteration 7 -- 121string(12) "101234567000" 122-- Iteration 8 -- 123string(13) "1.07654321E-9" 124-- Iteration 9 -- 125string(3) "0.5" 126-- Iteration 10 -- 127 128Warning: stripslashes() expects parameter 1 to be string, array given in %s on line %d 129NULL 130-- Iteration 11 -- 131 132Warning: stripslashes() expects parameter 1 to be string, array given in %s on line %d 133NULL 134-- Iteration 12 -- 135 136Warning: stripslashes() expects parameter 1 to be string, array given in %s on line %d 137NULL 138-- Iteration 13 -- 139 140Warning: stripslashes() expects parameter 1 to be string, array given in %s on line %d 141NULL 142-- Iteration 14 -- 143 144Warning: stripslashes() expects parameter 1 to be string, array given in %s on line %d 145NULL 146-- Iteration 15 -- 147string(1) "1" 148-- Iteration 16 -- 149string(0) "" 150-- Iteration 17 -- 151string(1) "1" 152-- Iteration 18 -- 153string(0) "" 154-- Iteration 19 -- 155string(0) "" 156-- Iteration 20 -- 157string(0) "" 158-- Iteration 21 -- 159string(0) "" 160-- Iteration 22 -- 161string(0) "" 162-- Iteration 23 -- 163string(6) "obj'ct" 164-- Iteration 24 -- 165 166Warning: stripslashes() expects parameter 1 to be string, resource given in %s on line %d 167NULL 168-- Iteration 25 -- 169string(0) "" 170-- Iteration 26 -- 171string(0) "" 172===DONE=== 173