473,881 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Singleton class scope problem

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:
class User
public function __construct ()

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?


Jul 17 '05
10 3024
Oli Filth wrote:
Variables (including class instances and static members) are not
shared between PHP runs.

Totally correct and this is indeed the true meaning of 'thread-safety'.
However, the term is often abused in PHP to indicate shared object access
during a script run as it was introduced into this discussion.

Jul 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: lawrence | last post by:
To call I would do something like: $headline = McSelectJustOneField::callDatastore("cbHeadline"); Is this the correct use of the static keyword, to implement a Singleton design?
by: Sharon | last post by:
I wish to build a framework for our developers that will include a singleton pattern. But it can not be a base class because it has a private constructor and therefore can be inherit. I thought maybe a Template can be use for that, but C# does not support Templates (will be C# generics in mid 2005). Does anyone have a solution on how the singleton pattern can be written, in C#, as a framework/ infrastructure class, so users can use this...
by: Robert W. | last post by:
I've just been reading all about the Singleton class and understand how to implement and use it but I cannot understand why one NEEDS to use it instead of just declaring a class and implementing Public Static variables therein. My usage revolves around global access to Reference Data. Some examples: - Countries, States-Provinces, Cities, Area Codes - Mobile Devices: Name, Description, Picture Filename and other sorts of data that will...
by: Chris Murphy via DotNetMonster.com | last post by:
Hey guys, I've been hitting a brick wall with a problem I've come accross in developing an application. Background: The application uses one primary class that I'm trying to implement with the singleton pattern in mind. The design pattern seems to be working properly (complex and simple variations of it) Serialzation/Deserialzation seems to work okay. I run into a problem when I attempt to load the file back into the
by: Michael Maes | last post by:
Hi, How would I make a class implementing a Singleton Pattern serializable. My problem is the Singleton Pattern 'requires' the constructor to be Private and serialization requires the constructor to be Public. Thanks, Michael
by: Rich | last post by:
The following code produced a singleton object with application scope when it should have had page scope: public class Singleton { private static Singleton uniqueInstance = null; private Singleton() { } public static Singleton getInstance()
by: Preets | last post by:
Can anyone explain to me the exact use of private constructors in c++ ?
by: John A Grandy | last post by:
For a singleton class utilizes by ASP.NET 2.0 page processing: When initial instantiation is performed during the initial call to the retrieve instance method (let's call the method "getInstance()"), an instantiated object of the class is assigned to the class' internal static reference to that an object of itself (let's call the reference "uniqueInstance") Does that uniqueInstance have global scope in the context of page processing ?
by: Tony Proctor | last post by:
I need to create a process Singleton object for an ASP application, but I'm having some odd issues In my GLOBAL.ASA, I have an <OBJECTelement specifying the relevant ProgID with RUNAT=Server and SCOPE=Application However, although this works fine for some classes, I get a permission denied error for classes from a particular DLL. The error response is:- Active Server Pages error '8002802b'
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.