ReflectionFunction_construct.001.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --TEST--
  2. ReflectionFunction constructor errors
  3. --CREDITS--
  4. Robin Fernandes <robinf@php.net>
  5. Steve Seear <stevseea@php.net>
  6. --FILE--
  7. <?php
  8. try {
  9. $a = new ReflectionFunction(array(1, 2, 3));
  10. echo "exception not thrown.".PHP_EOL;
  11. } catch (TypeError $re) {
  12. echo "Ok - ".$re->getMessage().PHP_EOL;
  13. }
  14. try {
  15. $a = new ReflectionFunction('nonExistentFunction');
  16. } catch (ReflectionException $e) {
  17. echo $e->getMessage().PHP_EOL;
  18. }
  19. try {
  20. $a = new ReflectionFunction();
  21. } catch (TypeError $re) {
  22. echo "Ok - ".$re->getMessage().PHP_EOL;
  23. }
  24. try {
  25. $a = new ReflectionFunction(1, 2);
  26. } catch (TypeError $re) {
  27. echo "Ok - ".$re->getMessage().PHP_EOL;
  28. }
  29. try {
  30. $a = new ReflectionFunction([]);
  31. } catch (TypeError $re) {
  32. echo "Ok - ".$re->getMessage().PHP_EOL;
  33. }
  34. ?>
  35. --EXPECT--
  36. Ok - ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, array given
  37. Function nonExistentFunction() does not exist
  38. Ok - ReflectionFunction::__construct() expects exactly 1 argument, 0 given
  39. Ok - ReflectionFunction::__construct() expects exactly 1 argument, 2 given
  40. Ok - ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, array given