]> granicus.if.org Git - php/blob
7e45eec411
[php] /
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
11 echo "*** Testing ReflectionMethod::getClosure() : error conditions ***\n";
12
13 class StaticExample
14 {
15     static function foo()
16     {
17         var_dump( "Static Example class, Hello World!" );
18     }
19 }
20
21 class Example
22 {
23     public $bar = 42;
24     public function foo()
25     {
26         var_dump( "Example class, bar: " . $this->bar );
27     }
28 }
29
30 // Initialize classes
31 $class = new ReflectionClass( 'Example' );
32 $staticclass = new ReflectionClass( 'StaticExample' );
33 $method = $class->getMethod( 'foo' );
34 $staticmethod = $staticclass->getMethod( 'foo' );
35 $object = new Example();
36 $fakeobj = new StdClass();
37
38 echo "\n-- Testing ReflectionMethod::getClosure() function with invalid object --\n";
39 try {
40         var_dump( $method->getClosure( $fakeobj ) );
41 } catch( Exception $e ) {
42         var_dump( $e->getMessage() );
43 }
44
45 ?>
46 --EXPECT--
47 *** Testing ReflectionMethod::getClosure() : error conditions ***
48
49 -- Testing ReflectionMethod::getClosure() function with invalid object --
50 string(72) "Given object is not an instance of the class this method was declared in"