1--TEST--
2Test strtr() function : usage variations - empty string & null for 'str' 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/* Testing strtr() function by passing the
12 *   empty string & null for 'str' argument and
13 *   corresponding translation pair of chars for 'from', 'to' & 'replace_pairs' arguments
14*/
15
16echo "*** Testing strtr() : empty string & null for 'str' arg ***\n";
17/* definitions of required input variables */
18$count = 1;
19
20$heredoc_str = <<<EOD
21
22EOD;
23
24//array of string inputs for $str
25$str_arr = array(
26  "",
27  '',
28  NULL,
29  null,
30  FALSE,
31  false,
32  $heredoc_str
33);
34
35$from = "";
36$to = "TEST";
37$replace_pairs = array("" => "t", '' => "TEST");
38
39
40/* loop through to test strtr() with each element of $str_arr */
41for($index = 0; $index < count($str_arr); $index++) {
42  echo "-- Iteration $count --\n";
43
44  $str = $str_arr[$index];  //getting the array element in 'str' variable
45
46  //strtr() call in three args syntax form
47  var_dump( strtr($str, $from, $to) );
48
49  //strtr() call in two args syntax form
50  var_dump( strtr($str, $replace_pairs) );
51
52  $count++;
53}
54echo "*** Done ***";
55?>
56--EXPECTF--
57*** Testing strtr() : empty string & null for 'str' arg ***
58-- Iteration 1 --
59string(0) ""
60string(0) ""
61-- Iteration 2 --
62string(0) ""
63string(0) ""
64-- Iteration 3 --
65string(0) ""
66string(0) ""
67-- Iteration 4 --
68string(0) ""
69string(0) ""
70-- Iteration 5 --
71string(0) ""
72string(0) ""
73-- Iteration 6 --
74string(0) ""
75string(0) ""
76-- Iteration 7 --
77string(0) ""
78string(0) ""
79*** Done ***
80