3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo "PHP_VERSION:".PHP_VERSION_ID."\n"; class C { private $x = 5; private function byRef(&$a) { $a *= 2; return $a; } private function byVal($b) { $b *= 3; return $b; } } $obj = new C(); $rp = new ReflectionProperty($obj, 'x'); try { echo "RP1:".$rp->getValue($obj)."\n"; } catch (Throwable $e) { echo "RP1_EX:".get_class($e)."\n"; } $rp2 = new ReflectionProperty($obj, 'x'); $rp2->setAccessible(true); try { echo "RP2:".$rp2->getValue($obj)."\n"; } catch (Throwable $e) { echo "RP2_EX:".get_class($e)."\n"; } $rp3 = new ReflectionProperty($obj, 'x'); $rp3->setAccessible(false); try { echo "RP3:".$rp3->getValue($obj)."\n"; } catch (Throwable $e) { echo "RP3_EX:".get_class($e)."\n"; } $rm1 = new ReflectionMethod($obj, 'byRef'); $arg = 10; try { $res = $rm1->invoke($obj, $arg); echo "RM1:$res/$arg\n"; } catch (Throwable $e) { echo "RM1_EX:".get_class($e)."\n"; } $rm2 = new ReflectionMethod($obj, 'byRef'); $arg2 = 10; $argsArr = [&$arg2]; try { $res2 = $rm2->invokeArgs($obj, $argsArr); echo "RM2:$res2/$arg2\n"; } catch (Throwable $e) { echo "RM2_EX:".get_class($e)."\n"; } $rm3 = new ReflectionMethod($obj, 'byVal'); $valArg = 7; try { $res3 = $rm3->invoke($obj, $valArg); echo "RM3:$res3/$valArg\n"; } catch (Throwable $e) { echo "RM3_EX:".get_class($e)."\n"; } $rm4 = new ReflectionMethod($obj, 'byVal'); $valArg2 = 7; $argsArr2 = [$valArg2]; try { $res4 = $rm4->invokeArgs($obj, $argsArr2); echo "RM4:$res4/$valArg2\n"; } catch (Throwable $e) { echo "RM4_EX:".get_class($e)."\n"; }
Output for git.master_jit, git.master
PHP_VERSION:80600 RP1:5 Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /in/LLbOH on line 12 RP2:5 Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /in/LLbOH on line 15 RP3:5 Warning: C::byRef(): Argument #1 ($a) must be passed by reference, value given in /in/LLbOH on line 20 RM1:20/10 RM2:20/20 RM3:21/7 RM4:21/7

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:
42.93 ms | 406 KiB | 5 Q