1--TEST-- 2ReflectionClass::newInstanceArgs 3--CREDITS-- 4Robin Fernandes <robinf@php.net> 5Steve Seear <stevseea@php.net> 6--FILE-- 7<?php 8class A { 9 public function A() { 10 echo "In constructor of class A\n"; 11 } 12} 13 14class B { 15 public function __construct($a, $b) { 16 echo "In constructor of class B with args $a, $b\n"; 17 } 18} 19 20class C { 21 protected function __construct() { 22 echo "In constructor of class C\n"; 23 } 24} 25 26class D { 27 private function __construct() { 28 echo "In constructor of class D\n"; 29 } 30} 31class 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')); 43var_dump($a1, $a2); 44 45$b1 = $rcB->newInstanceArgs(); 46$b2 = $rcB->newInstanceArgs(array('x', 123)); 47var_dump($b1, $b2); 48 49try { 50 $rcC->newInstanceArgs(); 51 echo "you should not see this\n"; 52} catch (Exception $e) { 53 echo $e->getMessage() . "\n"; 54} 55 56try { 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(); 64var_dump($e1); 65 66try { 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-- 74Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in %s on line %d 75In constructor of class A 76In constructor of class A 77object(A)#%d (0) { 78} 79object(A)#%d (0) { 80} 81 82Warning: Missing argument 1 for B::__construct() in %s on line 9 83 84Warning: Missing argument 2 for B::__construct() in %s on line 9 85 86Notice: Undefined variable: a in %s on line 10 87 88Notice: Undefined variable: b in %s on line 10 89In constructor of class B with args , 90In constructor of class B with args x, 123 91object(B)#%d (0) { 92} 93object(B)#%d (0) { 94} 95Access to non-public constructor of class C 96Access to non-public constructor of class D 97object(E)#%d (0) { 98} 99Class E does not have a constructor, so you cannot pass any constructor arguments 100