On my site I want to make two classes. One that can be instantiated
normally and one with extended functionality that can only be
instantiated once. The Singleton pattern thus seems like a logical
choice for the second class. However, I would like the second
(singleton) class to extend the first. Something like this:
<?php
class User
{
public function __construct ()
{
doSomething();
}
}
class Member extends User
{
private static $instance = NULL;
public static function getInstance ()
{
if (self::$instanc e === NULL)
self::$instance = new Member;
return self::$instance ;
}
private function __construct () {}
private function __clone () {}
}
?>
But this gives me the following error:
Fatal error: Access level to Member::__const ruct() must be public (as
in class User) in class.member.ph p on line 6
But I don't want the constructor to be public, because I want it to be
impossible to create more than one instance.
Does anybody know what to do about this?
Thanks.