Retrieve Singleton object from session
Posted: Thu Jun 21, 2007 7:49 pm
I've tried out this Singleton pattern for a few objects and it helps me with dealing with references versus copies that may occur (from not paying attention). However, I have an object (user login object) that I save to the session, and would like to retrieve. I created a SetInstance() function in order to allow this is be transportable, but I've run into a problem with the __CLASS__ magic constant.
Am I using __CLASS__ incorrectly? (I must be if I'm getting the error
)
Code: Select all
public function SetInstance($instance)
{
if(!$instance instanceof __CLASS__)
{
return;
}
self::$instance = $instance;
}Code: Select all
Parse error: syntax error, unexpected T_CLASS_C, expecting T_STRING or T_VARIABLE