3v4l.org

run code in 300+ PHP versions simultaneously
<?php class C { public \stdClass $x; public function __construct() { $this->x = new \stdClass(); } public function foo() { print "->foo()\n"; var_export($this->x); } } class D extends C { public function __get($name) { print "\n"; print "__get($name)\n"; var_export($this->$name); } } $c = new D(); // $c->x = NULL; print "\$c->x\n"; var_export($c->x); print "\n\n-----------------\n"; print "\$c->x after unset()\n"; unset($c->x); var_export($c->x); print "\n\n-----------------\n"; $c->foo();
based on M1uX2
Output for 7.4.0 - 7.4.9, 8.0.0alpha1 - beta1
$c->x (object) array( ) ----------------- $c->x after unset() __get(x) Fatal error: Uncaught Error: Typed property C::$x must not be accessed before initialization in /in/sY96q:21 Stack trace: #0 /in/sY96q(34): D->__get('x') #1 {main} thrown in /in/sY96q on line 21
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.21
Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting function (T_FUNCTION) or const (T_CONST) in /in/sY96q on line 4
Process exited with code 255.