3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class StaticExample { protected $thingyMoBobber = "Bob"; protected static $thing = "eh!"; public static $castles = "sand castles :3"; public static function playWithThing() { echo self::$thing; } public function heyBob() { echo "hey " . $this->thingyMoBobber; } public static function tryToDoBadThingsWithBob() { echo $this->thingyMoBobber; } } StaticExample::playWithThing(); echo StaticExample::$castles; $staticExample = new StaticExample(); $staticExample->heyBob(); // THESE DO NOT WORK StaticExample::heyBob(); StaticExample::tryToDoBadThingsWithBob();
Output for 7.0.0 - 7.2.0
eh!sand castles :3hey Bob Deprecated: Non-static method StaticExample::heyBob() should not be called statically in /in/0Ajbc on line 28 Fatal error: Uncaught Error: Using $this when not in object context in /in/0Ajbc:13 Stack trace: #0 /in/0Ajbc(28): StaticExample::heyBob() #1 {main} thrown in /in/0Ajbc on line 13
Process exited with code 255.
Output for 5.3.18 - 5.6.28
eh!sand castles :3hey Bob Strict Standards: Non-static method StaticExample::heyBob() should not be called statically in /in/0Ajbc on line 28 Fatal error: Using $this when not in object context in /in/0Ajbc on line 13
Process exited with code 255.