rtrim_variation2.phpt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. --TEST--
  2. Test rtrim() function : usage variations - test values for $charlist argument
  3. --FILE--
  4. <?php
  5. /* Prototype : string rtrim ( string $str [, string $charlist ] )
  6. * Description: Strip whitespace (or other characters) from the end of a string.
  7. * Source code: ext/standard/string.c
  8. */
  9. echo "*** Testing rtrim() function: with unexpected inputs for 'charlist' argument ***\n";
  10. //get an unset variable
  11. $unset_var = ' string_val ';
  12. unset($unset_var);
  13. //defining a class
  14. class sample {
  15. public function __toString() {
  16. return " sample object ";
  17. }
  18. }
  19. //getting the resource
  20. $file_handle = fopen(__FILE__, "r");
  21. // array with different values for $input
  22. $inputs = array (
  23. // integer values
  24. /*1*/ 0,
  25. 1,
  26. 255,
  27. 256,
  28. 2147483647,
  29. -2147483648,
  30. // float values
  31. /*7*/ 10.5,
  32. -20.5,
  33. 10.1234567e10,
  34. // array values
  35. /*10*/ array(),
  36. array(0),
  37. array(1, 2),
  38. // boolean values
  39. /*13*/ true,
  40. false,
  41. TRUE,
  42. FALSE,
  43. // null values
  44. /*17*/ NULL,
  45. null,
  46. // objects
  47. /*19*/ new sample(),
  48. // resource
  49. /*20*/ $file_handle,
  50. // undefined variable
  51. /*21*/ @$undefined_var,
  52. // unset variable
  53. /*22*/ @$unset_var
  54. );
  55. // loop through with each element of the $inputs array to test rtrim() function
  56. $count = 1;
  57. foreach($inputs as $charlist) {
  58. echo "-- Iteration $count --\n";
  59. // strip white space and any "minus" signs
  60. var_dump( rtrim("!---Hello World---!", $charlist) );
  61. $count ++;
  62. }
  63. fclose($file_handle); //closing the file handle
  64. ?>
  65. ===DONE===
  66. --EXPECTF--
  67. *** Testing rtrim() function: with unexpected inputs for 'charlist' argument ***
  68. -- Iteration 1 --
  69. string(19) "!---Hello World---!"
  70. -- Iteration 2 --
  71. string(19) "!---Hello World---!"
  72. -- Iteration 3 --
  73. string(19) "!---Hello World---!"
  74. -- Iteration 4 --
  75. string(19) "!---Hello World---!"
  76. -- Iteration 5 --
  77. string(19) "!---Hello World---!"
  78. -- Iteration 6 --
  79. string(19) "!---Hello World---!"
  80. -- Iteration 7 --
  81. string(19) "!---Hello World---!"
  82. -- Iteration 8 --
  83. string(19) "!---Hello World---!"
  84. -- Iteration 9 --
  85. string(19) "!---Hello World---!"
  86. -- Iteration 10 --
  87. Warning: rtrim() expects parameter 2 to be string, array given in %s on line %d
  88. NULL
  89. -- Iteration 11 --
  90. Warning: rtrim() expects parameter 2 to be string, array given in %s on line %d
  91. NULL
  92. -- Iteration 12 --
  93. Warning: rtrim() expects parameter 2 to be string, array given in %s on line %d
  94. NULL
  95. -- Iteration 13 --
  96. string(19) "!---Hello World---!"
  97. -- Iteration 14 --
  98. string(19) "!---Hello World---!"
  99. -- Iteration 15 --
  100. string(19) "!---Hello World---!"
  101. -- Iteration 16 --
  102. string(19) "!---Hello World---!"
  103. -- Iteration 17 --
  104. string(19) "!---Hello World---!"
  105. -- Iteration 18 --
  106. string(19) "!---Hello World---!"
  107. -- Iteration 19 --
  108. string(19) "!---Hello World---!"
  109. -- Iteration 20 --
  110. Warning: rtrim() expects parameter 2 to be string, resource given in %s on line %d
  111. NULL
  112. -- Iteration 21 --
  113. string(19) "!---Hello World---!"
  114. -- Iteration 22 --
  115. string(19) "!---Hello World---!"
  116. ===DONE===