formatter_fail.phpt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. --TEST--
  2. numfmt creation failures
  3. --EXTENSIONS--
  4. intl
  5. --FILE--
  6. <?php
  7. function err($fmt) {
  8. if(!$fmt) {
  9. echo var_export(intl_get_error_message(), true)."\n";
  10. }
  11. }
  12. function print_exception($e) {
  13. echo "\n" . get_class($e) . ": " . $e->getMessage()
  14. . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
  15. }
  16. function crt($t, $l, $s) {
  17. switch(true) {
  18. case $t == "O":
  19. try {
  20. return new NumberFormatter($l, $s);
  21. } catch (Throwable $e) {
  22. print_exception($e);
  23. return null;
  24. }
  25. break;
  26. case $t == "C":
  27. try {
  28. return NumberFormatter::create($l, $s);
  29. } catch (Throwable $e) {
  30. print_exception($e);
  31. return null;
  32. }
  33. break;
  34. case $t == "P":
  35. try {
  36. return numfmt_create($l, $s);
  37. } catch (Throwable $e) {
  38. print_exception($e);
  39. return null;
  40. }
  41. break;
  42. }
  43. }
  44. $args = array(
  45. array(null, null),
  46. array("whatever", 1234567),
  47. array(array(), array()),
  48. array("en", -1),
  49. array("en_US", NumberFormatter::PATTERN_RULEBASED),
  50. );
  51. try {
  52. $fmt = new NumberFormatter();
  53. } catch (TypeError $e) {
  54. print_exception($e);
  55. $fmt = null;
  56. }
  57. err($fmt);
  58. try {
  59. $fmt = numfmt_create();
  60. } catch (TypeError $e) {
  61. print_exception($e);
  62. $fmt = null;
  63. }
  64. err($fmt);
  65. try {
  66. $fmt = NumberFormatter::create();
  67. } catch (TypeError $e) {
  68. print_exception($e);
  69. $fmt = null;
  70. }
  71. err($fmt);
  72. $fmt = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
  73. try {
  74. $fmt->__construct('en_US', NumberFormatter::DECIMAL);
  75. } catch (Error $e) {
  76. print_exception($e);
  77. $fmt = null;
  78. }
  79. err($fmt);
  80. foreach($args as $arg) {
  81. $fmt = crt("O", $arg[0], $arg[1]);
  82. err($fmt);
  83. $fmt = crt("C", $arg[0], $arg[1]);
  84. err($fmt);
  85. $fmt = crt("P", $arg[0], $arg[1]);
  86. err($fmt);
  87. }
  88. ?>
  89. --EXPECTF--
  90. ArgumentCountError: NumberFormatter::__construct() expects at least 2 arguments, 0 given in %s on line %d
  91. 'U_ZERO_ERROR'
  92. ArgumentCountError: numfmt_create() expects at least 2 arguments, 0 given in %s on line %d
  93. 'U_ZERO_ERROR'
  94. ArgumentCountError: NumberFormatter::create() expects at least 2 arguments, 0 given in %s on line %d
  95. 'U_ZERO_ERROR'
  96. Error: NumberFormatter object is already constructed in %s on line %d
  97. 'U_ZERO_ERROR'
  98. Deprecated: NumberFormatter::__construct(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
  99. Deprecated: NumberFormatter::__construct(): Passing null to parameter #2 ($style) of type int is deprecated in %s on line %d
  100. Deprecated: NumberFormatter::create(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
  101. Deprecated: NumberFormatter::create(): Passing null to parameter #2 ($style) of type int is deprecated in %s on line %d
  102. Deprecated: numfmt_create(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
  103. Deprecated: numfmt_create(): Passing null to parameter #2 ($style) of type int is deprecated in %s on line %d
  104. IntlException: Constructor failed in %s on line %d
  105. 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
  106. 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
  107. 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
  108. TypeError: NumberFormatter::__construct(): Argument #1 ($locale) must be of type string, array given in %s on line %d
  109. 'U_ZERO_ERROR'
  110. TypeError: NumberFormatter::create(): Argument #1 ($locale) must be of type string, array given in %s on line %d
  111. 'U_ZERO_ERROR'
  112. TypeError: numfmt_create(): Argument #1 ($locale) must be of type string, array given in %s on line %d
  113. 'U_ZERO_ERROR'
  114. IntlException: Constructor failed in %s on line %d
  115. 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
  116. 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
  117. 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
  118. IntlException: Constructor failed in %s on line %d
  119. 'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR'
  120. 'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR'
  121. 'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR'