1--TEST--
2Test 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
11echo "*** Testing ReflectionMethod::getClosure() : error conditions ***\n";
12
13class StaticExample
14{
15	static function foo()
16	{
17		var_dump( "Static Example class, Hello World!" );
18	}
19}
20
21class 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
38echo "\n-- Testing ReflectionMethod::getClosure() function with more than expected no. of arguments --\n";
39var_dump( $staticmethod->getClosure( 'foobar' ) );
40var_dump( $staticmethod->getClosure( 'foo', 'bar' ) );
41var_dump( $method->getClosure( $object, 'foobar' ) );
42
43echo "\n-- Testing ReflectionMethod::getClosure() function with Zero arguments --\n";
44$closure = $method->getClosure();
45
46echo "\n-- Testing ReflectionMethod::getClosure() function with Zero arguments --\n";
47try {
48        var_dump( $method->getClosure( $fakeobj ) );
49} catch( Exception $e ) {
50        var_dump( $e->getMessage() );
51}
52
53?>
54===DONE===
55--EXPECTF--
56*** Testing ReflectionMethod::getClosure() : error conditions ***
57
58-- Testing ReflectionMethod::getClosure() function with more than expected no. of arguments --
59object(Closure)#%d (0) {
60}
61object(Closure)#%d (0) {
62}
63
64Warning: ReflectionMethod::getClosure() expects exactly 1 parameter, 2 given in %s on line %d
65NULL
66
67-- Testing ReflectionMethod::getClosure() function with Zero arguments --
68
69Warning: ReflectionMethod::getClosure() expects exactly 1 parameter, 0 given in %s on line %d
70
71-- Testing ReflectionMethod::getClosure() function with Zero arguments --
72string(72) "Given object is not an instance of the class this method was declared in"
73===DONE===
74