3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Visibility { public function __construct( public int $public, protected int $protected, private int $private, ) {} } $v = new Visibility(1, 2, 3); $reader = (fn (string $prop) => $this->$prop); $propReader = $reader->bindTo($v); var_dump($propReader('public')); var_dump($propReader('protected')); var_dump($propReader('private'));
Output for 8.0.0 - 8.0.13, 8.1rc1 - rc3
int(1) Fatal error: Uncaught Error: Cannot access protected property Visibility::$protected in /in/CXhqS:14 Stack trace: #0 /in/CXhqS(19): Closure->{closure}('protected') #1 {main} thrown in /in/CXhqS on line 14
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.26
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/CXhqS on line 6
Process exited with code 255.

preferences:
51.87 ms | 533 KiB | 13 Q