Annotation of embedaddon/php/ext/standard/tests/strings/strtr_variation7.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test strtr() function : usage variations - unexpected inputs for 'to' argument
3: --FILE--
4: <?php
5: /* Prototype : string strtr(string $str, string $from[, string $to]);
6: string strtr(string $str, array $replace_pairs);
7: * Description: Translates characters in str using given translation tables
8: * Source code: ext/standard/string.c
9: */
10:
11: /* Test strtr() function: with unexpected inputs for 'to'
12: * and expected types for 'str' & 'from' arguments
13: */
14:
15: echo "*** Testing strtr() function: with unexpected inputs for 'to' ***\n";
16:
17: //get an unset variable
18: $unset_var = 'string_val';
19: unset($unset_var);
20:
21: //defining a class
22: class sample {
23: public function __toString() {
24: return "sample object";
25: }
26: }
27:
28: //getting the resource
29: $file_handle = fopen(__FILE__, "r");
30:
31: //defining 'str' argument
32: $str = "012atm";
33:
34: //defining 'from' argument
35: $from = "atm012";
36:
37: // array of values for 'to' argument
38: $to_arr = array (
39:
40: // integer values
41: /*1*/ 0,
42: 1,
43: -2,
44:
45: // float values
46: /*4*/ 10.5,
47: -20.5,
48: 10.12345675e10,
49:
50: // array values
51: /*7*/ array(),
52: array(0),
53: array(1, 2),
54:
55: // boolean values
56: /*10*/ true,
57: false,
58: TRUE,
59: FALSE,
60:
61: // null vlaues
62: /*14*/ NULL,
63: null,
64:
65: // objects
66: /*16*/ new sample(),
67:
68: // resource
69: /*17*/ $file_handle,
70:
71: // undefined variable
72: /*18*/ @$undefined_var,
73:
74: // unset variable
75: /*19*/ @$unset_var
76: );
77:
78: // loop through with each element of the $to array to test strtr() function
79: $count = 1;
80: for($index = 0; $index < count($to_arr); $index++) {
81: echo "\n-- Iteration $count --\n";
82: $to = $to_arr[$index];
83: var_dump( strtr($str, $from, $to) );
84: $count ++;
85: }
86:
87: fclose($file_handle); //closing the file handle
88:
89: ?>
90: ===DONE===
91: --EXPECTF--
92: *** Testing strtr() function: with unexpected inputs for 'to' ***
93:
94: -- Iteration 1 --
95: string(6) "0120tm"
96:
97: -- Iteration 2 --
98: string(6) "0121tm"
99:
100: -- Iteration 3 --
101: string(6) "012-2m"
102:
103: -- Iteration 4 --
104: string(6) "51210."
105:
106: -- Iteration 5 --
107: string(6) ".52-20"
108:
109: -- Iteration 6 --
110: string(6) "234101"
111:
112: -- Iteration 7 --
113:
114: Warning: strtr() expects parameter 3 to be string, array given in %s on line %d
115: NULL
116:
117: -- Iteration 8 --
118:
119: Warning: strtr() expects parameter 3 to be string, array given in %s on line %d
120: NULL
121:
122: -- Iteration 9 --
123:
124: Warning: strtr() expects parameter 3 to be string, array given in %s on line %d
125: NULL
126:
127: -- Iteration 10 --
128: string(6) "0121tm"
129:
130: -- Iteration 11 --
131: string(6) "012atm"
132:
133: -- Iteration 12 --
134: string(6) "0121tm"
135:
136: -- Iteration 13 --
137: string(6) "012atm"
138:
139: -- Iteration 14 --
140: string(6) "012atm"
141:
142: -- Iteration 15 --
143: string(6) "012atm"
144:
145: -- Iteration 16 --
146: string(6) "plesam"
147:
148: -- Iteration 17 --
149:
150: Warning: strtr() expects parameter 3 to be string, resource given in %s on line %d
151: NULL
152:
153: -- Iteration 18 --
154: string(6) "012atm"
155:
156: -- Iteration 19 --
157: string(6) "012atm"
158: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>