Reputation: 1210
I use a Slim route to call RabbitBroker::setup()
and track its response.
The setup method will always go ahead and do the init proccess. It never returns the "already setup" message. I tried to use RabbitBroker::$isSetup
instead of self::$isSetup
.. Keeps forgeting the value.. Am I going crazy here?
class RabbitBroker
{
private static $isSetup = false;
public static function setup() {
if (self::$isSetup) return "Connection was set already setup";
self::$isSetup = true;
// do some init...
return "Connection is now set by init"
}
}
Upvotes: 1
Views: 93
Reputation: 11115
You are probably trying to share the value of a static variable between requests. PHP is stateless (like HTTP), because if this, each script execution has its own static variables.
So setting a static variable only set it for the current request and not for the following requests.
Upvotes: 1