3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Singleton { private static $instance = null; private function __construct() { } public static function getInstance() { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; } } $singleton = Singleton::getInstance(); try { $singleton = new Singleton(); } catch (Throwable $e) { echo $e->getMessage(); }
based on NguHO
Output for 7.0.0 - 7.2.0
Call to private Singleton::__construct() from invalid context
Output for 5.3.19 - 5.6.28
Fatal error: Call to private Singleton::__construct() from invalid context in /in/UqQR4 on line 20
Process exited with code 255.