3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bar{ public $state = "valid"; function baz($inject){ $this->state = "invalid"; $inject->qux(); $this->state = "valid"; } } $x = new Bar(); $x->baz(new class($x){ function __construct($x){ $this->x = $x; } function qux(){ echo $this->x->state . " pwned!"; } });
Output for 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Deprecated: Creation of dynamic property class@anonymous::$x is deprecated in /in/LU8U7 on line 19 invalid pwned!
Output for 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34
invalid pwned!
Output for 5.6.38
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/LU8U7 on line 17
Process exited with code 255.

preferences:
98.81 ms | 1613 KiB | 4 Q