#42830 [Opn->Bgs]: Implements Singleton with inheritance not possible

From: Date: Tue, 02 Oct 2007 14:14:45 +0000
Subject: #42830 [Opn->Bgs]: Implements Singleton with inheritance not possible
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-118097@lists.php.net to get a copy of this message
ID: 42830 Updated by: tony2001@php.net Reported By: raragao at raragao dot eng dot br -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: Windows XP / Debian PHP Version: 5.2.4 New Comment: abstract class Super { public function __construct () {} } => abstract class Super { private function __construct () {} } Previous Comments: ------------------------------------------------------------------------ [2007-10-02 13:03:43] raragao at raragao dot eng dot br Description: ------------ I can't implements a Singleton Pattern with inheritance. Reproduce code: --------------- abstract class Super { public function __construct () {} } class Sub extends Super { private static $object; private function __construct () {} public static function getInstance() { if (!(self::$object instanceof Sub)) { self::$object = new Sub(); } return self::$object; } } $a = Sub::getInstance(); Expected result: ---------------- That worked. Actual result: -------------- Fatal error: Access level to Sub::__construct() must be public (as in class Super) in E:\sources\curso\teste\ClasseA.php on line 16 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42830&edit=1

« previous php.bugs (#118097) next »