1--TEST-- 2Test setlocale() function : usage variations - Setting system locale as empty string 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) == 'WIN') { 6 die('skip Not valid for windows'); 7} 8if (setlocale(LC_ALL,'en_AU.utf8') === false || setlocale(LC_ALL,'en_US.utf8') === false) { 9 die('skip en_AU.utf8/en_US.utf8 locales not available'); 10} 11?> 12--ENV-- 13LC_ALL=en_US.utf8; 14--FILE-- 15<?php 16/* Prototype : string setlocale (int $category , string $locale [,string $..] ) 17 * : string setlocale(int $category , array $locale); 18 * Description: Sets locale information.Returns the new current locale , or FALSE 19 * if locale functionality is not implemented in this platform. 20 * Source code: ext/standard/string.c 21*/ 22 23/* If locale is empty string "", the locale names will be set from the values of environment variables with the same names as from ENV */ 24 25echo "*** Testing setlocale() : usage variations - setting system locale = \"\" ***\n"; 26 27//initially setting the locale 28setlocale(LC_ALL,'en_AU.utf8'); 29 30echo "Locale info, before setting the locale\n"; 31 32//returns current locale,before executing setlocale() . 33$locale_info_before = localeconv(); 34 35var_dump($locale_info_before); 36 37//Testing setlocale() by giving locale = null 38echo "Setting system locale, category = LC_ALL and locale = \"\"\n"; 39setlocale(LC_ALL, ""); 40 41echo "Locale info, after setting the locale\n"; 42 43//Returns Current locale,after executing setlocale(). 44$locale_info_after = localeconv(); 45 46var_dump($locale_info_after); 47 48echo "Checking new locale in the system, Expected : the locale names will be set from the values of environment variables\n"; 49echo "Test "; 50if($locale_info_before != $locale_info_after){ 51 echo "PASSED."; 52} else { 53 echo "FAILED."; 54} 55 56echo "\nDone\n"; 57?> 58--EXPECT-- 59*** Testing setlocale() : usage variations - setting system locale = "" *** 60Locale info, before setting the locale 61array(18) { 62 ["decimal_point"]=> 63 string(1) "." 64 ["thousands_sep"]=> 65 string(1) "," 66 ["int_curr_symbol"]=> 67 string(4) "AUD " 68 ["currency_symbol"]=> 69 string(1) "$" 70 ["mon_decimal_point"]=> 71 string(1) "." 72 ["mon_thousands_sep"]=> 73 string(1) "," 74 ["positive_sign"]=> 75 string(0) "" 76 ["negative_sign"]=> 77 string(1) "-" 78 ["int_frac_digits"]=> 79 int(2) 80 ["frac_digits"]=> 81 int(2) 82 ["p_cs_precedes"]=> 83 int(1) 84 ["p_sep_by_space"]=> 85 int(0) 86 ["n_cs_precedes"]=> 87 int(1) 88 ["n_sep_by_space"]=> 89 int(0) 90 ["p_sign_posn"]=> 91 int(1) 92 ["n_sign_posn"]=> 93 int(1) 94 ["grouping"]=> 95 array(2) { 96 [0]=> 97 int(3) 98 [1]=> 99 int(3) 100 } 101 ["mon_grouping"]=> 102 array(2) { 103 [0]=> 104 int(3) 105 [1]=> 106 int(3) 107 } 108} 109Setting system locale, category = LC_ALL and locale = "" 110Locale info, after setting the locale 111array(18) { 112 ["decimal_point"]=> 113 string(1) "." 114 ["thousands_sep"]=> 115 string(1) "," 116 ["int_curr_symbol"]=> 117 string(4) "USD " 118 ["currency_symbol"]=> 119 string(1) "$" 120 ["mon_decimal_point"]=> 121 string(1) "." 122 ["mon_thousands_sep"]=> 123 string(1) "," 124 ["positive_sign"]=> 125 string(0) "" 126 ["negative_sign"]=> 127 string(1) "-" 128 ["int_frac_digits"]=> 129 int(2) 130 ["frac_digits"]=> 131 int(2) 132 ["p_cs_precedes"]=> 133 int(1) 134 ["p_sep_by_space"]=> 135 int(0) 136 ["n_cs_precedes"]=> 137 int(1) 138 ["n_sep_by_space"]=> 139 int(0) 140 ["p_sign_posn"]=> 141 int(1) 142 ["n_sign_posn"]=> 143 int(1) 144 ["grouping"]=> 145 array(2) { 146 [0]=> 147 int(3) 148 [1]=> 149 int(3) 150 } 151 ["mon_grouping"]=> 152 array(2) { 153 [0]=> 154 int(3) 155 [1]=> 156 int(3) 157 } 158} 159Checking new locale in the system, Expected : the locale names will be set from the values of environment variables 160Test PASSED. 161Done 162