3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Singleton { public static function getInstance() { static $instance = null; if (null === $instance) { $instance = new static(); } return $instance; } abstract protected function __construct(){} // prevent new instances using "new" final private function __clone(){} // prevent cloning final private function __wakeup(){} // prevent unserializing } class odb extends Singleton { /*** Credentials ***/ private $sPDOHost = 'localhost'; private $sPDOUser = 'username'; private $sPDOPass = 'password'; private $sPDODB = 'database'; /*** Main Constructor ***/ private function __construct() { /*try { $this->oPDO = new PDO('mysql:host=' . $this->sPDOHost . ';' . 'dbname=' . $this->sPDODB, $this->sPDOUser, $this->sPDOPass); } catch (PDOException $oEx) { die('MySQL/PDO Connection failed: <br /><pre>' . $oEx->getMessage() . "</pre>"); return false; }*/ echo "hi"; } } $Test = odb::getInstance(); ?>
Output for 5.3.0 - 5.3.28, 5.4.0 - 5.4.29
Fatal error: Abstract function Singleton::__construct() cannot contain body in /in/qaG6N on line 14
Process exited with code 255.

preferences:
180.89 ms | 1395 KiB | 66 Q