Reputation: 3737
I recently ran across a problem: object properties are recreated every time a new object is created. The flow:
The point is to keep all the properties of class X by not creating a new instance of X if it has been already created once. What would be the best way to achieve this? Or maybe it is the flow itself that should be changed?
Thanks
Upvotes: 2
Views: 64
Reputation: 9173
$x = new Bootstrap();
and somewhere in the bootstrap class:
private function instance_maker ()
{
if($_SESSION['made_instance']=="")
{
//make instance
$m = new Subclass();
// set session to prevent further instanciation
$_SESSION['made_instance'] = true;
}
}
Upvotes: 1