key_error.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. --TEST--
  2. Test key() function : error conditions - Pass incorrect number of args
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed key(array $array_arg)
  6. * Description: Return the key of the element currently pointed to by the internal array pointer
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Pass incorrect number of arguments to key() to test behaviour
  11. */
  12. echo "*** Testing key() : error conditions ***\n";
  13. // Zero arguments
  14. echo "\n-- Testing key() function with Zero arguments --\n";
  15. var_dump( key() );
  16. //Test current with one more than the expected number of arguments
  17. echo "\n-- Testing key() function with more than expected no. of arguments --\n";
  18. $array_arg = array(1, 2);
  19. $extra_arg = 10;
  20. var_dump( key($array_arg, $extra_arg) );
  21. ?>
  22. ===DONE===
  23. --EXPECTF--
  24. *** Testing key() : error conditions ***
  25. -- Testing key() function with Zero arguments --
  26. Warning: key() expects exactly 1 parameter, 0 given in %s on line %d
  27. NULL
  28. -- Testing key() function with more than expected no. of arguments --
  29. Warning: key() expects exactly 1 parameter, 2 given in %s on line %d
  30. NULL
  31. ===DONE===