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 41try { 42 var_dump($rcA->newInstanceArgs()); 43} catch (Throwable $e) { 44 echo "Exception: " . $e->getMessage() . "\n"; 45} 46try { 47 var_dump($rcA->newInstanceArgs(array('x'))); 48} catch (Throwable $e) { 49 echo "Exception: " . $e->getMessage() . "\n"; 50} 51 52try { 53 var_dump($rcB->newInstanceArgs()); 54} catch (Throwable $e) { 55 echo "Exception: " . $e->getMessage() . "\n"; 56} 57try { 58 var_dump($rcB->newInstanceArgs(array('x', 123))); 59} catch (Throwable $e) { 60 echo "Exception: " . $e->getMessage() . "\n"; 61} 62 63try { 64 $rcC->newInstanceArgs(); 65 echo "you should not see this\n"; 66} catch (Exception $e) { 67 echo $e->getMessage() . "\n"; 68} 69 70try { 71 $rcD->newInstanceArgs(); 72 echo "you should not see this\n"; 73} catch (Exception $e) { 74 echo $e->getMessage() . "\n"; 75} 76 77$e1 = $rcE->newInstanceArgs(); 78var_dump($e1); 79 80try { 81 $e2 = $rcE->newInstanceArgs(array('x')); 82 echo "you should not see this\n"; 83} catch (Exception $e) { 84 echo $e->getMessage() . "\n"; 85} 86?> 87--EXPECTF-- 88Deprecated: 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 89In constructor of class A 90object(A)#%d (0) { 91} 92In constructor of class A 93object(A)#%d (0) { 94} 95Exception: Too few arguments to function B::__construct(), 0 passed and exactly 2 expected 96In constructor of class B with args x, 123 97object(B)#%d (0) { 98} 99Access to non-public constructor of class C 100Access to non-public constructor of class D 101object(E)#%d (0) { 102} 103Class E does not have a constructor, so you cannot pass any constructor arguments 104