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 { } $getReflectedConstructorParams = function($className) { return (new \ReflectionClass($className))->getConstructor()->getParameters(); }; $className = 'Controller'; $graph = [$className]; // I hate recursion, there's much better ways while (!empty($getReflectedConstructorParams($className))) { $className = $getReflectedConstructorParams($className); $graph[] = $className; } var_dump($className);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: ReflectionClass::__construct(): Argument #1 ($objectOrClass) must be of type object|string, array given in /in/Oa9Wk:9 Stack trace: #0 /in/Oa9Wk(9): ReflectionClass->__construct(Array) #1 /in/Oa9Wk(16): {closure}(Array) #2 {main} thrown in /in/Oa9Wk on line 9
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Notice: Array to string conversion in /in/Oa9Wk on line 9 Fatal error: Uncaught ReflectionException: Class Array does not exist in /in/Oa9Wk:9 Stack trace: #0 /in/Oa9Wk(9): ReflectionClass->__construct('Array') #1 /in/Oa9Wk(16): {closure}(Array) #2 {main} thrown in /in/Oa9Wk on line 9
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Fatal error: Uncaught ReflectionException: Class Array does not exist in /in/Oa9Wk:9 Stack trace: #0 /in/Oa9Wk(9): ReflectionClass->__construct('Array') #1 /in/Oa9Wk(16): {closure}(Array) #2 {main} thrown in /in/Oa9Wk on line 9
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Notice: Array to string conversion in /in/Oa9Wk on line 9 Fatal error: Uncaught exception 'ReflectionException' with message 'Class Array does not exist' in /in/Oa9Wk:9 Stack trace: #0 /in/Oa9Wk(9): ReflectionClass->__construct('Array') #1 /in/Oa9Wk(16): {closure}(Array) #2 {main} thrown in /in/Oa9Wk on line 9
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Fatal error: Can't use function return value in write context in /in/Oa9Wk on line 16
Process exited with code 255.

preferences:
182.86 ms | 401 KiB | 228 Q