array_reduce_variation1.phpt 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. Test array_reduce() function : variation
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed array_reduce(array input, mixed callback [, int initial])
  6. * Description: Iteratively reduce the array to a single value via the callback.
  7. * Source code: ext/standard/array.c
  8. * Alias to functions:
  9. */
  10. echo "*** Testing array_reduce() : variation ***\n";
  11. function oneArg($v) {
  12. return $v;
  13. }
  14. function threeArgs($v, $w, $x) {
  15. return $v + $w + $x;
  16. }
  17. $array = array(1);
  18. echo "\n--- Testing with a callback with too few parameters ---\n";
  19. var_dump(array_reduce($array, "oneArg", 2));
  20. echo "\n--- Testing with a callback with too many parameters ---\n";
  21. try {
  22. var_dump(array_reduce($array, "threeArgs", 2));
  23. } catch (Throwable $e) {
  24. echo "Exception: " . $e->getMessage() . "\n";
  25. }
  26. ?>
  27. ===DONE===
  28. --EXPECT--
  29. *** Testing array_reduce() : variation ***
  30. --- Testing with a callback with too few parameters ---
  31. int(2)
  32. --- Testing with a callback with too many parameters ---
  33. Exception: Too few arguments to function threeArgs(), 2 passed and exactly 3 expected
  34. ===DONE===