ReflectionMethod_getClosure_error.phpt 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --TEST--
  2. Test ReflectionMethod::getClosure() function : error functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : public mixed ReflectionFunction::getClosure()
  6. * Description: Returns a dynamically created closure for the method
  7. * Source code: ext/reflection/php_reflection.c
  8. * Alias to functions:
  9. */
  10. echo "*** Testing ReflectionMethod::getClosure() : error conditions ***\n";
  11. class StaticExample
  12. {
  13. static function foo()
  14. {
  15. var_dump( "Static Example class, Hello World!" );
  16. }
  17. }
  18. class Example
  19. {
  20. public $bar = 42;
  21. public function foo()
  22. {
  23. var_dump( "Example class, bar: " . $this->bar );
  24. }
  25. }
  26. // Initialize classes
  27. $class = new ReflectionClass( 'Example' );
  28. $staticclass = new ReflectionClass( 'StaticExample' );
  29. $method = $class->getMethod( 'foo' );
  30. $staticmethod = $staticclass->getMethod( 'foo' );
  31. $object = new Example();
  32. $fakeobj = new StdClass();
  33. echo "\n-- Testing ReflectionMethod::getClosure() function with more than expected no. of arguments --\n";
  34. var_dump( $staticmethod->getClosure( 'foobar' ) );
  35. var_dump( $staticmethod->getClosure( 'foo', 'bar' ) );
  36. var_dump( $method->getClosure( $object, 'foobar' ) );
  37. echo "\n-- Testing ReflectionMethod::getClosure() function with Zero arguments --\n";
  38. $closure = $method->getClosure();
  39. echo "\n-- Testing ReflectionMethod::getClosure() function with Zero arguments --\n";
  40. try {
  41. var_dump( $method->getClosure( $fakeobj ) );
  42. } catch( Exception $e ) {
  43. var_dump( $e->getMessage() );
  44. }
  45. ?>
  46. ===DONE===
  47. --EXPECTF--
  48. *** Testing ReflectionMethod::getClosure() : error conditions ***
  49. -- Testing ReflectionMethod::getClosure() function with more than expected no. of arguments --
  50. object(Closure)#%d (0) {
  51. }
  52. object(Closure)#%d (0) {
  53. }
  54. Warning: ReflectionMethod::getClosure() expects exactly 1 parameter, 2 given in %s on line %d
  55. NULL
  56. -- Testing ReflectionMethod::getClosure() function with Zero arguments --
  57. Warning: ReflectionMethod::getClosure() expects exactly 1 parameter, 0 given in %s on line %d
  58. -- Testing ReflectionMethod::getClosure() function with Zero arguments --
  59. string(72) "Given object is not an instance of the class this method was declared in"
  60. ===DONE===