Annotation of embedaddon/php/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: ReflectionClass::newInstanceArgs
! 3: --CREDITS--
! 4: Robin Fernandes <robinf@php.net>
! 5: Steve Seear <stevseea@php.net>
! 6: --FILE--
! 7: <?php
! 8: class A {
! 9: public function A() {
! 10: echo "In constructor of class A\n";
! 11: }
! 12: }
! 13:
! 14: class B {
! 15: public function __construct($a, $b) {
! 16: echo "In constructor of class B with args $a, $b\n";
! 17: }
! 18: }
! 19:
! 20: class C {
! 21: protected function __construct() {
! 22: echo "In constructor of class C\n";
! 23: }
! 24: }
! 25:
! 26: class D {
! 27: private function __construct() {
! 28: echo "In constructor of class D\n";
! 29: }
! 30: }
! 31: class E {
! 32: }
! 33:
! 34:
! 35: $rcA = new ReflectionClass('A');
! 36: $rcB = new ReflectionClass('B');
! 37: $rcC = new ReflectionClass('C');
! 38: $rcD = new ReflectionClass('D');
! 39: $rcE = new ReflectionClass('E');
! 40:
! 41: $a1 = $rcA->newInstanceArgs();
! 42: $a2 = $rcA->newInstanceArgs(array('x'));
! 43: var_dump($a1, $a2);
! 44:
! 45: $b1 = $rcB->newInstanceArgs();
! 46: $b2 = $rcB->newInstanceArgs(array('x', 123));
! 47: var_dump($b1, $b2);
! 48:
! 49: try {
! 50: $rcC->newInstanceArgs();
! 51: echo "you should not see this\n";
! 52: } catch (Exception $e) {
! 53: echo $e->getMessage() . "\n";
! 54: }
! 55:
! 56: try {
! 57: $rcD->newInstanceArgs();
! 58: echo "you should not see this\n";
! 59: } catch (Exception $e) {
! 60: echo $e->getMessage() . "\n";
! 61: }
! 62:
! 63: $e1 = $rcE->newInstanceArgs();
! 64: var_dump($e1);
! 65:
! 66: try {
! 67: $e2 = $rcE->newInstanceArgs(array('x'));
! 68: echo "you should not see this\n";
! 69: } catch (Exception $e) {
! 70: echo $e->getMessage() . "\n";
! 71: }
! 72: ?>
! 73: --EXPECTF--
! 74: In constructor of class A
! 75: In constructor of class A
! 76: object(A)#%d (0) {
! 77: }
! 78: object(A)#%d (0) {
! 79: }
! 80:
! 81: Warning: Missing argument 1 for B::__construct() in %s on line 9
! 82:
! 83: Warning: Missing argument 2 for B::__construct() in %s on line 9
! 84:
! 85: Notice: Undefined variable: a in %s on line 10
! 86:
! 87: Notice: Undefined variable: b in %s on line 10
! 88: In constructor of class B with args ,
! 89: In constructor of class B with args x, 123
! 90: object(B)#%d (0) {
! 91: }
! 92: object(B)#%d (0) {
! 93: }
! 94: Access to non-public constructor of class C
! 95: Access to non-public constructor of class D
! 96: object(E)#%d (0) {
! 97: }
! 98: Class E does not have a constructor, so you cannot pass any constructor arguments
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>