Annotation of embedaddon/php/ext/standard/tests/strings/stripcslashes_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test 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:
15: echo "*** Testing stripcslashes() : with non-string type argument ***\n";
16: // initialize all required variables
17:
18: // get an unset variable
19: $unset_var = 'string_val';
20: unset($unset_var);
21:
22: // declaring a class
23: class 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 arugment is supplied with different values
85: echo "\n--- Testing stripcslashes() by supplying different values for 'str' argument ---\n";
86: $counter = 1;
87: for($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
97: fclose($file_handle);
98:
99: ?>
100: ===DONE===
101: --EXPECTF--
102: *** Testing stripcslashes() : with non-string type argument ***
103:
104: Notice: Undefined variable: undefined_var in %s on line %d
105:
106: Notice: Undefined variable: unset_var in %s on line %d
107:
108: --- Testing stripcslashes() by supplying different values for 'str' argument ---
109: -- Iteration 1 --
110: string(1) "0"
111: -- Iteration 2 --
112: string(1) "1"
113: -- Iteration 3 --
114: string(5) "12345"
115: -- Iteration 4 --
116: string(5) "-2345"
117: -- Iteration 5 --
118: string(4) "10.5"
119: -- Iteration 6 --
120: string(5) "-10.5"
121: -- Iteration 7 --
122: string(12) "101234567000"
123: -- Iteration 8 --
124: string(13) "1.07654321E-9"
125: -- Iteration 9 --
126: string(3) "0.5"
127: -- Iteration 10 --
128:
129: Warning: stripcslashes() expects parameter 1 to be string, array given in %s on line %d
130: NULL
131: -- Iteration 11 --
132:
133: Warning: stripcslashes() expects parameter 1 to be string, array given in %s on line %d
134: NULL
135: -- Iteration 12 --
136:
137: Warning: stripcslashes() expects parameter 1 to be string, array given in %s on line %d
138: NULL
139: -- Iteration 13 --
140:
141: Warning: stripcslashes() expects parameter 1 to be string, array given in %s on line %d
142: NULL
143: -- Iteration 14 --
144:
145: Warning: stripcslashes() expects parameter 1 to be string, array given in %s on line %d
146: NULL
147: -- Iteration 15 --
148: string(1) "1"
149: -- Iteration 16 --
150: string(0) ""
151: -- Iteration 17 --
152: string(1) "1"
153: -- Iteration 18 --
154: string(0) ""
155: -- Iteration 19 --
156: string(0) ""
157: -- Iteration 20 --
158: string(0) ""
159: -- Iteration 21 --
160: string(0) ""
161: -- Iteration 22 --
162: string(0) ""
163: -- Iteration 23 --
164: string(6) "obj'ct"
165: -- Iteration 24 --
166:
167: Warning: stripcslashes() expects parameter 1 to be string, resource given in %s on line %d
168: NULL
169: -- Iteration 25 --
170: string(0) ""
171: -- Iteration 26 --
172: string(0) ""
173: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>