array_map_variation18.phpt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. --TEST--
  2. Test array_map() function : usage variations - unexpected values for 'arr1' 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 non array values in place of $arr1
  11. */
  12. echo "*** Testing array_map() : unexpected values for 'arr1' ***\n";
  13. function callback($a)
  14. {
  15. return $a;
  16. }
  17. //get an unset array variable
  18. $unset_var1 = array(1, 2);
  19. unset ($unset_var1);
  20. // get an unset variable
  21. $unset_var2 = 10;
  22. unset ($unset_var2);
  23. // get a class
  24. class classA
  25. {
  26. public function __toString() {
  27. return "Class A object";
  28. }
  29. }
  30. // heredoc string
  31. $heredoc = <<<EOT
  32. hello world
  33. EOT;
  34. // get a resource variable
  35. $fp = fopen(__FILE__, "r");
  36. // different scalar/non-scalar values for array input
  37. $unexpected_inputs = array(
  38. // int data
  39. /*1*/ 0,
  40. 1,
  41. 12345,
  42. -2345,
  43. // float data
  44. /*5*/ 10.5,
  45. -10.5,
  46. 12.3456789000e10,
  47. 12.3456789000E-10,
  48. .5,
  49. // null data
  50. /*10*/ NULL,
  51. null,
  52. // boolean data
  53. /*12*/ true,
  54. false,
  55. TRUE,
  56. FALSE,
  57. // empty data
  58. /*16*/ "",
  59. '',
  60. // string data
  61. /*18*/ "string",
  62. 'string',
  63. $heredoc,
  64. // object data
  65. /*21*/ new classA(),
  66. // undefined data
  67. /*22*/ @$undefined_var,
  68. // unset data
  69. /*23*/ @$unset_var1,
  70. @$unset_var2,
  71. // resource variable
  72. /*25*/ $fp
  73. );
  74. // loop through each element of $unexpected_inputs to check the behavior of array_map
  75. for($count = 0; $count < count($unexpected_inputs); $count++) {
  76. echo "-- Iteration ".($count + 1)." --\n";
  77. var_dump( array_map('callback', $unexpected_inputs[$count]));
  78. };
  79. fclose($fp);
  80. echo "Done";
  81. ?>
  82. --EXPECTF--
  83. *** Testing array_map() : unexpected values for 'arr1' ***
  84. -- Iteration 1 --
  85. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  86. NULL
  87. -- Iteration 2 --
  88. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  89. NULL
  90. -- Iteration 3 --
  91. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  92. NULL
  93. -- Iteration 4 --
  94. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  95. NULL
  96. -- Iteration 5 --
  97. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  98. NULL
  99. -- Iteration 6 --
  100. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  101. NULL
  102. -- Iteration 7 --
  103. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  104. NULL
  105. -- Iteration 8 --
  106. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  107. NULL
  108. -- Iteration 9 --
  109. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  110. NULL
  111. -- Iteration 10 --
  112. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  113. NULL
  114. -- Iteration 11 --
  115. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  116. NULL
  117. -- Iteration 12 --
  118. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  119. NULL
  120. -- Iteration 13 --
  121. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  122. NULL
  123. -- Iteration 14 --
  124. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  125. NULL
  126. -- Iteration 15 --
  127. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  128. NULL
  129. -- Iteration 16 --
  130. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  131. NULL
  132. -- Iteration 17 --
  133. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  134. NULL
  135. -- Iteration 18 --
  136. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  137. NULL
  138. -- Iteration 19 --
  139. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  140. NULL
  141. -- Iteration 20 --
  142. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  143. NULL
  144. -- Iteration 21 --
  145. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  146. NULL
  147. -- Iteration 22 --
  148. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  149. NULL
  150. -- Iteration 23 --
  151. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  152. NULL
  153. -- Iteration 24 --
  154. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  155. NULL
  156. -- Iteration 25 --
  157. Warning: array_map(): Argument #2 should be an array in %s on line %d%d
  158. NULL
  159. Done