3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php interface proxy {} trait assertFinal { private function assertFinal() { if (is_subclass_of($this, __CLASS__, false) && !$this instanceof proxy) { trigger_error('Nein! Class is final!', E_USER_NOTICE); } } } class finalfoo { use assertFinal; public function __construct() { $this->assertFinal(); } } class fooproxy extends finalfoo implements proxy { } class naughtyfoo extends finalfoo { } echo "new finalfoo: "; try {new finalfoo; echo "yes";} catch (\Exception $e) { echo "no"; } echo "\n"; echo "new fooproxy: "; try {new fooproxy; echo "yes";} catch (\Exception $e) { echo "no"; } echo "\n"; echo "new naughtyfoo: "; try {new naughtyfoo; echo "yes";} catch (\Exception $e) { echo "no"; } echo "\n";
based on knmhZ
Output for 5.4.9 - 7.2.0
new finalfoo: yes new fooproxy: yes new naughtyfoo: Notice: Nein! Class is final! in /in/HUYkX on line 10 yes
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/HUYkX on line 5
Process exited with code 255.