3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A {} class B {} class C {} class D {} class Z { use ConstructorParamDeprecationHelper; public function __construct( protected A $a, protected C|B $c, protected D|C $d, ) { $this->deprecateParam(B::class, 'c', func_get_args()); var_dump(get_class($this->a)); var_dump(get_class($this->c)); var_dump(get_class($this->d)); } } new Z(new A(), new B(), new C(), new D()); new Z(new A(), new C(), new D()); trait ConstructorParamDeprecationHelper { function deprecateParam($className, $paramName, $args) { if ($this->$paramName instanceof $className) { trigger_error('A, B, C, D is deprecated, pass A, C, D instead', E_USER_DEPRECATED); $constructor = new ReflectionMethod($this, '__construct'); $params = $constructor->getParameters(); $position = array_search($paramName, array_column($params, 'name')); $move = array_slice($params, $position, NULL, TRUE); foreach ($move as $i => $param) { $this->{$param->getName()} = $args[$i + 1]; } } } }
Output for git.master
/bin/php-git-master: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-git-master) /bin/php-git-master: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-git-master)
Process exited with code 1.
Output for git.master_jit, rfc.property-hooks
Deprecated: A, B, C, D is deprecated, pass A, C, D instead in /in/MtHNJ on line 28 string(1) "A" string(1) "C" string(1) "D" string(1) "A" string(1) "C" string(1) "D"

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:
30.57 ms | 401 KiB | 8 Q