array_map_variation16.phpt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --TEST--
  2. Test array_map() function : usage variations - failing built-in functions & language constructs
  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-permmited built-in functions and language constructs i.e.
  11. * echo(), array(), empty(), eval(), exit(), isset(), list(), print()
  12. */
  13. echo "*** Testing array_map() : non-permmited built-in functions ***\n";
  14. // array to be passed as arguments
  15. $arr1 = array(1, 2);
  16. // built-in functions & language constructs
  17. $callback_names = array(
  18. /*1*/ 'echo',
  19. 'array',
  20. 'empty',
  21. /*4*/ 'eval',
  22. 'exit',
  23. 'isset',
  24. 'list',
  25. /*8*/ 'print'
  26. );
  27. for($count = 0; $count < count($callback_names); $count++)
  28. {
  29. echo "-- Iteration ".($count + 1)." --\n";
  30. var_dump( array_map($callback_names[$count], $arr1) );
  31. }
  32. echo "Done";
  33. ?>
  34. --EXPECTF--
  35. *** Testing array_map() : non-permmited built-in functions ***
  36. -- Iteration 1 --
  37. Warning: array_map() expects parameter 1 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d
  38. NULL
  39. -- Iteration 2 --
  40. Warning: array_map() expects parameter 1 to be a valid callback, function 'array' not found or invalid function name in %s on line %d
  41. NULL
  42. -- Iteration 3 --
  43. Warning: array_map() expects parameter 1 to be a valid callback, function 'empty' not found or invalid function name in %s on line %d
  44. NULL
  45. -- Iteration 4 --
  46. Warning: array_map() expects parameter 1 to be a valid callback, function 'eval' not found or invalid function name in %s on line %d
  47. NULL
  48. -- Iteration 5 --
  49. Warning: array_map() expects parameter 1 to be a valid callback, function 'exit' not found or invalid function name in %s on line %d
  50. NULL
  51. -- Iteration 6 --
  52. Warning: array_map() expects parameter 1 to be a valid callback, function 'isset' not found or invalid function name in %s on line %d
  53. NULL
  54. -- Iteration 7 --
  55. Warning: array_map() expects parameter 1 to be a valid callback, function 'list' not found or invalid function name in %s on line %d
  56. NULL
  57. -- Iteration 8 --
  58. Warning: array_map() expects parameter 1 to be a valid callback, function 'print' not found or invalid function name in %s on line %d
  59. NULL
  60. Done