3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php trait MyTrait { private $abc = 1; public static function increment($by) { $this->abc += $by; } public function getValue() { return $this->abc; } } class MyClass { use MyTrait; public function increment() { MyTrait::increment(1); } } $c = new MyClass; $c->increment(); $c->increment(); var_dump($c->getValue());
based on bI8FR
Output for 7.0.0 - 7.3.0beta1
Fatal error: Uncaught Error: Using $this when not in object context in /in/ptmU9:8 Stack trace: #0 /in/ptmU9(23): MyTrait::increment(1) #1 /in/ptmU9(28): MyClass->increment() #2 {main} thrown in /in/ptmU9 on line 8
Process exited with code 255.
Output for hhvm-3.22.0
Fatal error: Uncaught Error: $this is null in /in/ptmU9:-1 Stack trace: #0 /in/ptmU9(-1): MyTrait::increment() #1 /in/ptmU9(-1): MyClass->increment() #2 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Fatal error: Uncaught Error: $this is null in /in/ptmU9:8 Stack trace: #0 /in/ptmU9(23): MyTrait::increment() #1 /in/ptmU9(28): MyClass->increment() #2 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Fatal error: Using $this when not in object context in /in/ptmU9 on line 8
Process exited with code 255.