Re: [PHP] Singletons

2008-10-20 Thread Jochem Maas
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

Re: [PHP] Singletons

2008-10-20 Thread Christoph Boget
> 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

Re: [PHP] Singletons

2008-10-20 Thread Stut
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

Re: [PHP] Singletons

2008-10-20 Thread Christoph Boget
> 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

Re: [PHP] Singletons

2008-10-20 Thread Tony Marston
""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

Re: [PHP] Singletons

2008-10-20 Thread Stut
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

Re: [PHP] Singletons

2008-10-20 Thread Christoph Boget
>> 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

Re: [PHP] Singletons

2008-10-20 Thread Stut
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

Re: [PHP] Singletons

2008-10-20 Thread n3or
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

Re: [PHP] Singletons

2008-10-20 Thread Christoph Boget
>> 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

Re: [PHP] Singletons

2008-10-20 Thread Eric Butera
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

Re: [PHP] Singletons

2008-10-20 Thread n3or
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

[PHP] Singletons

2008-10-20 Thread Christoph Boget
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::__construct()'; if( !is_null( singleTon::$thisObj )) { echo '$thisObj alre