3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Controller { public function __construct(B $b) { $this->b = $b; } } class B { public function __construct(C $c) { $this->c = $c; } } class C { public function __construct(Guzzle $guzzle) { $this->guzzle = $guzzle; } } class Guzzle { public function __construct() { } } $getReflectedConstructorParams = function($className) { return (new ReflectionClass($className))->getConstructor()->getParameters(); }; $className = 'Controller'; $graph = []; // I hate recursion, there's much better ways while (true) { $params = $getReflectedConstructorParams($className); // Guard clause if (!isset($params[0])) { // We'll have reached the Guzzle object here, the last one in the chain $prevObj = null; foreach ($graph as $obj) { if ($prevObj === null) { $prevObj = new $obj; continue; } $prevObj = new $obj($prevObj); } var_dump($prevObj); break; } $className = $params[0]->getClass()->getName(); $graph[] = $className; } var_dump($graph);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/2kWFU on line 42 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/2kWFU on line 42 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/2kWFU on line 42 Fatal error: Uncaught ArgumentCountError: Too few arguments to function B::__construct(), 0 passed in /in/2kWFU on line 29 and exactly 1 expected in /in/2kWFU:4 Stack trace: #0 /in/2kWFU(29): B->__construct() #1 {main} thrown in /in/2kWFU on line 4
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
54.82 ms | 402 KiB | 8 Q