ReflectionClass_getMethod_002.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --TEST--
  2. ReflectionClass::getMethod() - error cases
  3. --CREDITS--
  4. Robin Fernandes <robinf@php.net>
  5. Steve Seear <stevseea@php.net>
  6. --FILE--
  7. <?php
  8. class C {
  9. function f() {}
  10. }
  11. $rc = new ReflectionClass("C");
  12. echo "Check invalid params:\n";
  13. try {
  14. var_dump($rc->getMethod());
  15. } catch (TypeError $e) {
  16. echo $e->getMessage() . "\n";
  17. }
  18. try {
  19. var_dump($rc->getMethod("f", "f"));
  20. } catch (TypeError $e) {
  21. echo $e->getMessage() . "\n";
  22. }
  23. try {
  24. var_dump($rc->getMethod(null));
  25. } catch (Exception $e) {
  26. echo $e->getMessage() . "\n";
  27. }
  28. try {
  29. var_dump($rc->getMethod(1));
  30. } catch (Exception $e) {
  31. echo $e->getMessage() . "\n";
  32. }
  33. try {
  34. var_dump($rc->getMethod(1.5));
  35. } catch (Exception $e) {
  36. echo $e->getMessage() . "\n";
  37. }
  38. try {
  39. var_dump($rc->getMethod(true));
  40. } catch (Exception $e) {
  41. echo $e->getMessage() . "\n";
  42. }
  43. try {
  44. var_dump($rc->getMethod(array(1,2,3)));
  45. } catch (TypeError $e) {
  46. echo $e->getMessage() . "\n";
  47. }
  48. try {
  49. var_dump($rc->getMethod(new C));
  50. } catch (TypeError $e) {
  51. echo $e->getMessage() . "\n";
  52. }
  53. ?>
  54. --EXPECTF--
  55. Check invalid params:
  56. ReflectionClass::getMethod() expects exactly 1 argument, 0 given
  57. ReflectionClass::getMethod() expects exactly 1 argument, 2 given
  58. Deprecated: ReflectionClass::getMethod(): Passing null to parameter #1 ($name) of type string is deprecated in %s on line %d
  59. Method C::() does not exist
  60. Method C::1() does not exist
  61. Method C::1.5() does not exist
  62. Method C::1() does not exist
  63. ReflectionClass::getMethod(): Argument #1 ($name) must be of type string, array given
  64. ReflectionClass::getMethod(): Argument #1 ($name) must be of type string, C given