Christoph Boget schreef:
>> Create your singleton class without extending the class you need to extend.
>> Create an instance of that class in your object. Implement the __call magic
>> method to proxy function calls through to that instance throwing an
>> exception (or error) if the method request
> Create your singleton class without extending the class you need to extend.
> Create an instance of that class in your object. Implement the __call magic
> method to proxy function calls through to that instance throwing an
> exception (or error) if the method requested doesn't exist. Not particu
On 20 Oct 2008, at 21:06, Christoph Boget wrote:
Why can't it be a separate class,
In general, it can. In my case, it can't. Not unless I want to
completely duplicate an already existing class.
Create your singleton class without extending the class you need to
extend. Create an instance
> There is absolutely nothing in PHP which prevents you from implementing the
> singleton pattern.
It does if the constructor must be public.
> but your attempt is doomed to failure. What makes you think that a singleton
> class has to inherit from another class?
Nothing at all. Except that in
""Christoph Boget"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
>
>> Singletons are not rocket science, but as with all patterns you really
>> need
>> to understand the theory before trying to implement and use it.
>
> Agreed. But apparently implementing them in PHP leaves th
On 20 Oct 2008, at 20:24, Christoph Boget wrote:
public function __construct()
A singleton would usually have a private constructor to prevent
non-singleton instances.
The problem being if the class in question derives from another class
that has a public constructor... If you are in that pa
>> public function __construct()
> A singleton would usually have a private constructor to prevent
> non-singleton instances.
The problem being if the class in question derives from another class
that has a public constructor... If you are in that particular
situation (which I am), you're basic
On 20 Oct 2008, at 18:07, Christoph Boget wrote:
Ok, so why isn't this working as (I, at the very least) expected?
Hmm, where to start...
class singleTon
{
private static $thisObj = NULL;
private $thisProp = NULL;
public function __construct()
A singleton would usually have a pr
Christoph Boget schrieb:
Apart from making the constructor
private, is there any way I can ensure that there is ever only one
instance of an object?
you could use the magic method __clone.
For example:
public function __clone() { trigger_error('The singleton pattern avoids
cloning this in
>> Apart from making the constructor
>> private, is there any way I can ensure that there is ever only one
>> instance of an object?
> you could use the magic method __clone.
> For example:
> public function __clone() { trigger_error('The singleton pattern avoids
> cloning this instance', E_USER_ER
On Mon, Oct 20, 2008 at 1:07 PM, Christoph Boget
<[EMAIL PROTECTED]> wrote:
> Ok, so why isn't this working as (I, at the very least) expected?
>
> class singleTon
> {
>private static $thisObj = NULL;
>private $thisProp = NULL;
>
>public function __construct()
>{
> echo 'singleTon
Christoph Boget schrieb:
Apart from making the constructor
private, is there any way I can ensure that there is ever only one
instance of an object?
you could use the magic method __clone.
For example:
public function __clone() { trigger_error('The singleton pattern avoids
cloning this instanc
12 matches
Mail list logo