We all know how bad Singletons are because they hide dependencies and for other reasons.
But in a framework, there could be many objects that need t
For me, I try to avoid global constants, singletons for a simple reason, there are cases when I might need to APIs running.
For example, i have front-end and admin. Inside admin, I want them to be able to login as a user. Consider the code inside admin.
$frontend = new Frontend();
$frontend->auth->login($_GET['user']);
$frontend->redirect('/');
This may establish new database connection, new logger etc for the frontend initialization and check if user actually exists, valid etc. It also would use proper separate cookie and location services.
My idea of singleton is - You can't add same object inside parent twice. For instance
$logger1=$api->add('Logger');
$logger2=$api->add('Logger');
would leave you with a single instance and both variables pointing to it.
Finally if you want to use object oriented development, then work with objects, not with classes.