|
Posted by ks on 01/23/06 21:23
Hello,
I'm kinda new to PHP and I'm running into something that just seems
odd. There's a good chance I'm just doing something wrong though. I'm
trying to implement a simple singleton:
private static $instance;
public static function Instance()
{
if (!isset(self::$instance))
{
self::$instance = new MyClass();
}
return self::$instance;
}
which pretty much follows the common pattern. I've noticed through,
either by using a var_dump on self::$instance or by simply outputting
"test" inside the IF statement, that my if statement always executes.
If I call Instance twice within the same request, the singleton works,
but if I refresh or open a new browser, each request seems to create
it's own version. Am I doing something wrong or are static's scoped to
thread requests? I would expect the block within the if to fire once
throughout the life of the application (or until php resets itself or
whatever).
I'm just messing with things on IIS - incase that could be the issue.
Navigation:
[Reply to this message]
|