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