Annotation of embedaddon/php/ext/standard/tests/strings/strval_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test strval() function : usage variations - Pass different data types as strval
3: --FILE--
4: <?php
5: /* Prototype : string strval ( mixed $var )
6: * Description: Get the string value of a variable.
7: * Source code: ext/standard/string.c
8: */
9:
10: echo "*** Testing strval() : usage variations ***\n";
11:
12: error_reporting(E_ALL ^ E_NOTICE);
13:
14: //get an unset variable
15: $unset_var = 10;
16: unset ($unset_var);
17:
18: //getting the resource
19: $file_handle = fopen(__FILE__, "r");
20:
21: class MyClass
22: {
23: function __toString() {
24: return "MyClass";
25: }
26: }
27:
28: //array of values to iterate over
29: $values = array(
30: //Decimal values
31: /*1*/ 0,
32: 1,
33: 12345,
34: -12345,
35:
36: //Octal values
37: /*5*/ 02,
38: 010,
39: 030071,
40: -030071,
41:
42: //Hexadecimal values
43: /*9*/ 0x0,
44: 0x1,
45: 0xABCD,
46: -0xABCD,
47:
48: // float data
49: /*13*/ 100.5,
50: -100.5,
51: 100.1234567e10,
52: 100.7654321E-10,
53: .5,
54:
55: // array data
56: /*18*/ array(),
57: array('color' => 'red', 'item' => 'pen'),
58:
59: // null data
60: /*20*/ NULL,
61: null,
62:
63: // boolean data
64: /*22*/ true,
65: false,
66: TRUE,
67: FALSE,
68:
69: // empty data
70: /*26*/ "",
71: '',
72:
73: // object data
74: /*28*/ new MyClass(),
75:
76: // resource
77: /*29*/ $file_handle,
78:
79: // undefined data
80: /*30*/ @$undefined_var,
81:
82: // unset data
83: /*31*/ @$unset_var,
84: );
85:
86: // loop through each element of the array for strval
87: $iterator = 1;
88: foreach($values as $value) {
89: echo "\n-- Iteration $iterator --\n";
90: var_dump( strval($value) );
91: $iterator++;
92: };
93: ?>
94: ===DONE===
95: --EXPECTF--
96: *** Testing strval() : usage variations ***
97:
98: -- Iteration 1 --
99: string(1) "0"
100:
101: -- Iteration 2 --
102: string(1) "1"
103:
104: -- Iteration 3 --
105: string(5) "12345"
106:
107: -- Iteration 4 --
108: string(6) "-12345"
109:
110: -- Iteration 5 --
111: string(1) "2"
112:
113: -- Iteration 6 --
114: string(1) "8"
115:
116: -- Iteration 7 --
117: string(5) "12345"
118:
119: -- Iteration 8 --
120: string(6) "-12345"
121:
122: -- Iteration 9 --
123: string(1) "0"
124:
125: -- Iteration 10 --
126: string(1) "1"
127:
128: -- Iteration 11 --
129: string(5) "43981"
130:
131: -- Iteration 12 --
132: string(6) "-43981"
133:
134: -- Iteration 13 --
135: string(5) "100.5"
136:
137: -- Iteration 14 --
138: string(6) "-100.5"
139:
140: -- Iteration 15 --
141: string(13) "1001234567000"
142:
143: -- Iteration 16 --
144: string(14) "1.007654321E-8"
145:
146: -- Iteration 17 --
147: string(3) "0.5"
148:
149: -- Iteration 18 --
150: string(5) "Array"
151:
152: -- Iteration 19 --
153: string(5) "Array"
154:
155: -- Iteration 20 --
156: string(0) ""
157:
158: -- Iteration 21 --
159: string(0) ""
160:
161: -- Iteration 22 --
162: string(1) "1"
163:
164: -- Iteration 23 --
165: string(0) ""
166:
167: -- Iteration 24 --
168: string(1) "1"
169:
170: -- Iteration 25 --
171: string(0) ""
172:
173: -- Iteration 26 --
174: string(0) ""
175:
176: -- Iteration 27 --
177: string(0) ""
178:
179: -- Iteration 28 --
180: string(7) "MyClass"
181:
182: -- Iteration 29 --
183: string(%d) "Resource id #%d"
184:
185: -- Iteration 30 --
186: string(0) ""
187:
188: -- Iteration 31 --
189: string(0) ""
190: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>