3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Database { private static $database; private function __construct() { // Nothing } public static function getInstance() { if (!self::$database) { self::$database = new Database(); } return self::$database; } } class BasicMath { public function getString($string) { return $string; } public static function add($number1, $number2) { $this->getString('hEllo'); return $number1 + $number2; } } var_dump(BasicMath::add(1, 2));
based on Y96At
Output for 7.0.0 - 7.3.0rc3
Fatal error: Uncaught Error: Using $this when not in object context in /in/PBg0b:30 Stack trace: #0 /in/PBg0b(35): BasicMath::add(1, 2) #1 {main} thrown in /in/PBg0b on line 30
Process exited with code 255.
Output for 5.3.20 - 5.6.21
Fatal error: Using $this when not in object context in /in/PBg0b on line 30
Process exited with code 255.