12-31-2009, 06:24 AM
|
#17 (permalink)
|
|
The Contributor
Join Date: Feb 2007
Posts: 61
Thanks: 9
|
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.
|
|
|
|