|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-10-02 13:03 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 16:00:02 2025 UTC |
abstract class Super { public function __construct () {} } => abstract class Super { private function __construct () {} }