1--TEST--
2ReflectionClass::newInstanceArgs
3--CREDITS--
4Robin Fernandes <robinf@php.net>
5Steve Seear <stevseea@php.net>
6--FILE--
7<?php
8
9class B {
10    public function __construct($a, $b) {
11        echo "In constructor of class B with args $a, $b\n";
12    }
13}
14
15class C {
16    protected function __construct() {
17        echo "In constructor of class C\n";
18    }
19}
20
21class D {
22    private function __construct() {
23        echo "In constructor of class D\n";
24    }
25}
26class E {
27}
28
29
30$rcB = new ReflectionClass('B');
31$rcC = new ReflectionClass('C');
32$rcD = new ReflectionClass('D');
33$rcE = new ReflectionClass('E');
34
35try {
36    $rcB->newInstanceArgs();
37} catch (Throwable $e) {
38    echo "Exception: " . $e->getMessage() . "\n";
39}
40
41var_dump($rcB->newInstanceArgs(array('x', 123)));
42
43try {
44    $rcC->newInstanceArgs();
45    echo "you should not see this\n";
46} catch (Exception $e) {
47    echo $e->getMessage() . "\n";
48}
49
50try {
51    $rcD->newInstanceArgs();
52    echo "you should not see this\n";
53} catch (Exception $e) {
54    echo $e->getMessage() . "\n";
55}
56
57$e1 = $rcE->newInstanceArgs();
58var_dump($e1);
59
60try {
61    $e2 = $rcE->newInstanceArgs(array('x'));
62    echo "you should not see this\n";
63} catch (Exception $e) {
64    echo $e->getMessage() . "\n";
65}
66?>
67--EXPECTF--
68Exception: Too few arguments to function B::__construct(), 0 passed and exactly 2 expected
69In constructor of class B with args x, 123
70object(B)#%d (0) {
71}
72Access to non-public constructor of class C
73Access to non-public constructor of class D
74object(E)#%d (0) {
75}
76Class E does not have a constructor, so you cannot pass any constructor arguments
77