mb_encode_mimeheader_variation1.phpt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. --TEST--
  2. Test mb_encode_mimeheader() function : usage variations - Pass different data types to $str arg
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_encode_mimeheader') or die("skip mb_encode_mimeheader() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : string mb_encode_mimeheader
  11. * (string $str [, string $charset [, string $transfer_encoding [, string $linefeed [, int $indent]]]])
  12. * Description: Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?=
  13. * Source code: ext/mbstring/mbstring.c
  14. */
  15. /*
  16. * Pass different data types to $str argument to see how mb_encode_mimeheader() behaves
  17. */
  18. echo "*** Testing mb_encode_mimeheader() : usage variations ***\n";
  19. // Initialise function arguments not being substituted
  20. $charset = 'utf-8';
  21. $transfer_encoding = 'B';
  22. $linefeed = "\r\n";
  23. $indent = 2;
  24. //get an unset variable
  25. $unset_var = 10;
  26. unset ($unset_var);
  27. // get a class
  28. class classA
  29. {
  30. public function __toString() {
  31. return "Class A object";
  32. }
  33. }
  34. // heredoc string
  35. $heredoc = <<<EOT
  36. hello world
  37. EOT;
  38. // get a resource variable
  39. $fp = fopen(__FILE__, "r");
  40. // unexpected values to be passed to $str argument
  41. $inputs = array(
  42. // int data
  43. /*1*/ 0,
  44. 1,
  45. 12345,
  46. -2345,
  47. // float data
  48. /*5*/ 10.5,
  49. -10.5,
  50. 12.3456789000e10,
  51. 12.3456789000E-10,
  52. .5,
  53. // null data
  54. /*10*/ NULL,
  55. null,
  56. // boolean data
  57. /*12*/ true,
  58. false,
  59. TRUE,
  60. FALSE,
  61. // empty data
  62. /*16*/ "",
  63. '',
  64. // string data
  65. /*18*/ "string",
  66. 'string',
  67. $heredoc,
  68. // object data
  69. /*21*/ new classA(),
  70. // undefined data
  71. /*22*/ @$undefined_var,
  72. // unset data
  73. /*23*/ @$unset_var,
  74. // resource variable
  75. /*24*/ $fp
  76. );
  77. // loop through each element of $inputs to check the behavior of mb_encode_mimeheader()
  78. $iterator = 1;
  79. foreach($inputs as $input) {
  80. echo "\n-- Iteration $iterator --\n";
  81. var_dump( mb_encode_mimeheader($input, $charset, $transfer_encoding, $linefeed, $indent));
  82. $iterator++;
  83. };
  84. fclose($fp);
  85. echo "Done";
  86. ?>
  87. --EXPECTF--
  88. *** Testing mb_encode_mimeheader() : usage variations ***
  89. -- Iteration 1 --
  90. string(1) "0"
  91. -- Iteration 2 --
  92. string(1) "1"
  93. -- Iteration 3 --
  94. string(5) "12345"
  95. -- Iteration 4 --
  96. string(5) "-2345"
  97. -- Iteration 5 --
  98. string(4) "10.5"
  99. -- Iteration 6 --
  100. string(5) "-10.5"
  101. -- Iteration 7 --
  102. string(12) "123456789000"
  103. -- Iteration 8 --
  104. string(13) "1.23456789E-9"
  105. -- Iteration 9 --
  106. string(3) "0.5"
  107. -- Iteration 10 --
  108. string(0) ""
  109. -- Iteration 11 --
  110. string(0) ""
  111. -- Iteration 12 --
  112. string(1) "1"
  113. -- Iteration 13 --
  114. string(0) ""
  115. -- Iteration 14 --
  116. string(1) "1"
  117. -- Iteration 15 --
  118. string(0) ""
  119. -- Iteration 16 --
  120. string(0) ""
  121. -- Iteration 17 --
  122. string(0) ""
  123. -- Iteration 18 --
  124. string(6) "string"
  125. -- Iteration 19 --
  126. string(6) "string"
  127. -- Iteration 20 --
  128. string(11) "hello world"
  129. -- Iteration 21 --
  130. string(14) "Class A object"
  131. -- Iteration 22 --
  132. string(0) ""
  133. -- Iteration 23 --
  134. string(0) ""
  135. -- Iteration 24 --
  136. Warning: mb_encode_mimeheader() expects parameter 1 to be string, resource given in %s on line %d
  137. NULL
  138. Done