Annotation of embedaddon/php/ext/reflection/tests/ReflectionMethod_invoke_error1.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: ReflectionMethod::invoke() errors
! 3: --FILE--
! 4: <?php
! 5:
! 6: class TestClass {
! 7: public $prop = 2;
! 8:
! 9: public function foo() {
! 10: echo "Called foo(), property = $this->prop\n";
! 11: var_dump($this);
! 12: return "Return Val";
! 13: }
! 14:
! 15: private static function privateMethod() {
! 16: echo "Called privateMethod()\n";
! 17: }
! 18: }
! 19:
! 20: abstract class AbstractClass {
! 21: abstract function foo();
! 22: }
! 23:
! 24: $foo = new ReflectionMethod('TestClass', 'foo');
! 25: $privateMethod = new ReflectionMethod("TestClass::privateMethod");
! 26:
! 27: $testClassInstance = new TestClass();
! 28: $testClassInstance->prop = "Hello";
! 29:
! 30: echo "invoke() on a non-object:\n";
! 31: try {
! 32: var_dump($foo->invoke(true));
! 33: } catch (ReflectionException $e) {
! 34: var_dump($e->getMessage());
! 35: }
! 36:
! 37: echo "\ninvoke() on a non-instance:\n";
! 38: try {
! 39: var_dump($foo->invoke(new stdClass()));
! 40: } catch (ReflectionException $e) {
! 41: var_dump($e->getMessage());
! 42: }
! 43:
! 44: echo "\nPrivate method:\n";
! 45: try {
! 46: var_dump($privateMethod->invoke($testClassInstance));
! 47: } catch (ReflectionException $e) {
! 48: var_dump($e->getMessage());
! 49: }
! 50:
! 51: echo "\nAbstract method:\n";
! 52: $abstractMethod = new ReflectionMethod("AbstractClass::foo");
! 53: try {
! 54: $abstractMethod->invoke(true);
! 55: } catch (ReflectionException $e) {
! 56: var_dump($e->getMessage());
! 57: }
! 58:
! 59: ?>
! 60: --EXPECTF--
! 61: invoke() on a non-object:
! 62: string(29) "Non-object passed to Invoke()"
! 63:
! 64: invoke() on a non-instance:
! 65: string(72) "Given object is not an instance of the class this method was declared in"
! 66:
! 67: Private method:
! 68: string(86) "Trying to invoke private method TestClass::privateMethod() from scope ReflectionMethod"
! 69:
! 70: Abstract method:
! 71: string(53) "Trying to invoke abstract method AbstractClass::foo()"
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>