View Single Post
Old 12-31-2009, 06:24 AM   #17 (permalink)
Killswitch
The Contributor
 
Join Date: Feb 2007
Posts: 61
Thanks: 9
Killswitch is on a distinguished road
Default

I have been using the Singleton for awhile now and ran into unexpected results with an app recently.

I most often used the singleton to get an instance of a class throughout several parts of a framework I wrote. No other method other than the singleton instance was static.

When I used it, it would return the wrong results. For example, an authorization controller I wrote, upon checking if a used was logged in ( a simple bool ), would always return false. Then I tried this...

Code:
if (Authorization::instance()->logged_in() === false)
which fixed the problem. If it helps, I also had a factory method for chaining and what not. I know the singleton was setup right to return the instance, I just don't know what was causing the issue and still haven't figured it out. Maybe authorization was just a bad idea for a singleton, but either way its working quite well now.
Killswitch is offline  
Reply With Quote