array_pad.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. --TEST--
  2. array_pad() tests
  3. --FILE--
  4. <?php
  5. var_dump(array_pad(array(), 1, 0));
  6. var_dump(array_pad(array(), 0, 0));
  7. var_dump(array_pad(array(), -1, 0));
  8. var_dump(array_pad(array("", -1, 2.0), 5, 0));
  9. var_dump(array_pad(array("", -1, 2.0), 5, array()));
  10. var_dump(array_pad(array("", -1, 2.0), 2, array()));
  11. var_dump(array_pad(array("", -1, 2.0), -3, array()));
  12. var_dump(array_pad(array("", -1, 2.0), -4, array()));
  13. try {
  14. var_dump(array_pad(array("", -1, 2.0), 2000000, 0));
  15. } catch (\ValueError $e) {
  16. echo $e->getMessage() . "\n";
  17. }
  18. ?>
  19. --EXPECT--
  20. array(1) {
  21. [0]=>
  22. int(0)
  23. }
  24. array(0) {
  25. }
  26. array(1) {
  27. [0]=>
  28. int(0)
  29. }
  30. array(5) {
  31. [0]=>
  32. string(0) ""
  33. [1]=>
  34. int(-1)
  35. [2]=>
  36. float(2)
  37. [3]=>
  38. int(0)
  39. [4]=>
  40. int(0)
  41. }
  42. array(5) {
  43. [0]=>
  44. string(0) ""
  45. [1]=>
  46. int(-1)
  47. [2]=>
  48. float(2)
  49. [3]=>
  50. array(0) {
  51. }
  52. [4]=>
  53. array(0) {
  54. }
  55. }
  56. array(3) {
  57. [0]=>
  58. string(0) ""
  59. [1]=>
  60. int(-1)
  61. [2]=>
  62. float(2)
  63. }
  64. array(3) {
  65. [0]=>
  66. string(0) ""
  67. [1]=>
  68. int(-1)
  69. [2]=>
  70. float(2)
  71. }
  72. array(4) {
  73. [0]=>
  74. array(0) {
  75. }
  76. [1]=>
  77. string(0) ""
  78. [2]=>
  79. int(-1)
  80. [3]=>
  81. float(2)
  82. }
  83. array_pad(): Argument #2 ($length) must be less than or equal to 1048576