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 8.5.1
PHP_VERSION:80501 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
Output for 8.5.0
PHP_VERSION:80500 RP1:5 Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in /in/LLbOH on line 12 RP2:5 Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect 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
Output for 8.4.16
PHP_VERSION:80416 RP1:5 RP2:5 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
Output for 8.4.15
PHP_VERSION:80415 RP1:5 RP2:5 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
Output for 8.4.14
PHP_VERSION:80414 RP1:5 RP2:5 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
Output for 8.4.13
PHP_VERSION:80413 RP1:5 RP2:5 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
Output for 8.4.12
PHP_VERSION:80412 RP1:5 RP2:5 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
Output for 8.4.11
PHP_VERSION:80411 RP1:5 RP2:5 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
Output for 8.4.10
PHP_VERSION:80410 RP1:5 RP2:5 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
Output for 8.4.9
PHP_VERSION:80409 RP1:5 RP2:5 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
Output for 8.4.8
PHP_VERSION:80408 RP1:5 RP2:5 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
Output for 8.4.7
PHP_VERSION:80407 RP1:5 RP2:5 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
Output for 8.4.6
PHP_VERSION:80406 RP1:5 RP2:5 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
Output for 8.4.5
PHP_VERSION:80405 RP1:5 RP2:5 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
Output for 8.4.4
PHP_VERSION:80404 RP1:5 RP2:5 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
Output for 8.4.3
PHP_VERSION:80403 RP1:5 RP2:5 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
Output for 8.4.2
PHP_VERSION:80402 RP1:5 RP2:5 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
Output for 8.4.1
PHP_VERSION:80401 RP1:5 RP2:5 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
Output for 8.3.29
PHP_VERSION:80329 RP1:5 RP2:5 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
Output for 8.3.28
PHP_VERSION:80328 RP1:5 RP2:5 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
Output for 8.3.27
PHP_VERSION:80327 RP1:5 RP2:5 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
Output for 8.3.26
PHP_VERSION:80326 RP1:5 RP2:5 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
Output for 8.3.25
PHP_VERSION:80325 RP1:5 RP2:5 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
Output for 8.3.24
PHP_VERSION:80324 RP1:5 RP2:5 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
Output for 8.3.23
PHP_VERSION:80323 RP1:5 RP2:5 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
Output for 8.3.22
PHP_VERSION:80322 RP1:5 RP2:5 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
Output for 8.3.21
PHP_VERSION:80321 RP1:5 RP2:5 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
Output for 8.3.20
PHP_VERSION:80320 RP1:5 RP2:5 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
Output for 8.3.19
PHP_VERSION:80319 RP1:5 RP2:5 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
Output for 8.3.18
PHP_VERSION:80318 RP1:5 RP2:5 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
Output for 8.3.17
PHP_VERSION:80317 RP1:5 RP2:5 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
Output for 8.3.16
PHP_VERSION:80316 RP1:5 RP2:5 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
Output for 8.3.15
PHP_VERSION:80315 RP1:5 RP2:5 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
Output for 8.3.14
PHP_VERSION:80314 RP1:5 RP2:5 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
Output for 8.3.13
PHP_VERSION:80313 RP1:5 RP2:5 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
Output for 8.3.12
PHP_VERSION:80312 RP1:5 RP2:5 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
Output for 8.3.11
PHP_VERSION:80311 RP1:5 RP2:5 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
Output for 8.3.10
PHP_VERSION:80310 RP1:5 RP2:5 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
Output for 8.3.9
PHP_VERSION:80309 RP1:5 RP2:5 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
Output for 8.3.8
PHP_VERSION:80308 RP1:5 RP2:5 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
Output for 8.3.7
PHP_VERSION:80307 RP1:5 RP2:5 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
Output for 8.3.6
PHP_VERSION:80306 RP1:5 RP2:5 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
Output for 8.3.5
PHP_VERSION:80305 RP1:5 RP2:5 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
Output for 8.3.4
PHP_VERSION:80304 RP1:5 RP2:5 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
Output for 8.3.3
PHP_VERSION:80303 RP1:5 RP2:5 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
Output for 8.3.2
PHP_VERSION:80302 RP1:5 RP2:5 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
Output for 8.3.1
PHP_VERSION:80301 RP1:5 RP2:5 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
Output for 8.3.0
PHP_VERSION:80300 RP1:5 RP2:5 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
Output for 8.2.30
PHP_VERSION:80230 RP1:5 RP2:5 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
Output for 8.2.29
PHP_VERSION:80229 RP1:5 RP2:5 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
Output for 8.2.28
PHP_VERSION:80228 RP1:5 RP2:5 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
Output for 8.2.27
PHP_VERSION:80227 RP1:5 RP2:5 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
Output for 8.1.34
PHP_VERSION:80134 RP1:5 RP2:5 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
Output for 8.0.30
PHP_VERSION:80030 RP1_EX:ReflectionException RP2:5 RP3_EX:ReflectionException RM1_EX:ReflectionException RM2_EX:ReflectionException RM3_EX:ReflectionException RM4_EX:ReflectionException
Output for 7.4.33
PHP_VERSION:70433 RP1_EX:ReflectionException RP2:5 RP3_EX:ReflectionException RM1_EX:ReflectionException RM2_EX:ReflectionException RM3_EX:ReflectionException RM4_EX:ReflectionException
Output for 7.1.33
PHP_VERSION:70133 RP1_EX:ReflectionException RP2:5 RP3_EX:ReflectionException RM1_EX:ReflectionException RM2_EX:ReflectionException RM3_EX:ReflectionException RM4_EX:ReflectionException
Output for 7.0.33
PHP_VERSION:70033 RP1_EX:ReflectionException RP2:5 RP3_EX:ReflectionException RM1_EX:ReflectionException RM2_EX:ReflectionException RM3_EX:ReflectionException RM4_EX:ReflectionException
Output for 5.6.40
PHP_VERSION:50640 Fatal error: Uncaught exception 'ReflectionException' with message 'Cannot access non-public member C::x' in /in/LLbOH:10 Stack trace: #0 /in/LLbOH(10): ReflectionProperty->getValue(Object(C)) #1 {main} thrown in /in/LLbOH on line 10
Process exited with code 255.

preferences:
54.71 ms | 493 KiB | 5 Q