is there a way to prevent the instance of the same class in a PHP script?
$user = new User();
$user2 = new User(); // I want to catch another instance of the user class and throw an exception
I have tried creating a static variable and manipulating it with a static function:
User::instance()
but that doesn’t stop me from doing:
$user = new User();
1 Answer