array_map_variation17.phpt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. --TEST--
  2. Test array_map() function : usage variations - unexpected values for 'callback' argument
  3. --FILE--
  4. <?php
  5. /* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] )
  6. * Description: Applies the callback to the elements of the given arrays
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Test array_map() by passing different scalar/nonscalar values in place of $callback
  11. */
  12. echo "*** Testing array_map() : unexpected values for 'callback' argument ***\n";
  13. $arr1 = array(1, 2, 3);
  14. // get a class
  15. class classA
  16. {
  17. public function __toString() {
  18. return "Class A object";
  19. }
  20. }
  21. // get a resource variable
  22. $fp = fopen(__FILE__, "r");
  23. // unexpected values to be passed to $input argument
  24. $unexpected_callbacks = array(
  25. // int data
  26. /*1*/ 0,
  27. 1,
  28. 12345,
  29. -2345,
  30. // float data
  31. /*5*/ 10.5,
  32. -10.5,
  33. 12.3456789000e10,
  34. 12.3456789000E-10,
  35. .5,
  36. // boolean data
  37. /*10*/ true,
  38. false,
  39. TRUE,
  40. FALSE,
  41. // empty data
  42. /*14*/ "",
  43. '',
  44. // array data
  45. /*16*/ array(),
  46. array(1, 2),
  47. array(1, array(2)),
  48. // object data
  49. /*19*/ new classA(),
  50. // resource variable
  51. /*20*/ $fp
  52. );
  53. // loop through each element of $inputs to check the behavior of array_map
  54. for($count = 0; $count < count($unexpected_callbacks); $count++) {
  55. echo "\n-- Iteration ".($count + 1)." --";
  56. var_dump( array_map($unexpected_callbacks[$count], $arr1));
  57. };
  58. fclose($fp);
  59. echo "Done";
  60. ?>
  61. --EXPECTF--
  62. *** Testing array_map() : unexpected values for 'callback' argument ***
  63. -- Iteration 1 --
  64. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  65. NULL
  66. -- Iteration 2 --
  67. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  68. NULL
  69. -- Iteration 3 --
  70. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  71. NULL
  72. -- Iteration 4 --
  73. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  74. NULL
  75. -- Iteration 5 --
  76. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  77. NULL
  78. -- Iteration 6 --
  79. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  80. NULL
  81. -- Iteration 7 --
  82. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  83. NULL
  84. -- Iteration 8 --
  85. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  86. NULL
  87. -- Iteration 9 --
  88. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  89. NULL
  90. -- Iteration 10 --
  91. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  92. NULL
  93. -- Iteration 11 --
  94. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  95. NULL
  96. -- Iteration 12 --
  97. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  98. NULL
  99. -- Iteration 13 --
  100. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  101. NULL
  102. -- Iteration 14 --
  103. Warning: array_map() expects parameter 1 to be a valid callback, function '' not found or invalid function name in %s on line %d
  104. NULL
  105. -- Iteration 15 --
  106. Warning: array_map() expects parameter 1 to be a valid callback, function '' not found or invalid function name in %s on line %d
  107. NULL
  108. -- Iteration 16 --
  109. Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in %s on line %d
  110. NULL
  111. -- Iteration 17 --
  112. Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in %s on line %d
  113. NULL
  114. -- Iteration 18 --
  115. Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in %s on line %d
  116. NULL
  117. -- Iteration 19 --
  118. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  119. NULL
  120. -- Iteration 20 --
  121. Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d
  122. NULL
  123. Done