mb_strtolower_variation1.phpt 2.8 KB

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