I\'ve learn a while ago on StackOverflow that we can get the \"instance ID\" of any resource, for instance:
var_dump(intval(curl_init())); // int(2)
var_dum
What you're trying to do, is actually Aspect-Oriented Programming (AOP).
There are at least a couple of frameworks available for AOP in PHP at this point:
This may be overkill for your needs, but you may find that exploring the kind of thinking behind ideas like these will lead you down the rabbithole, and teach you new ways to think about software development in general - AOP is a powerful concept, allowing you to program in terms of strategies and concerns, or "aspects".
Languages like PHP were designed to solve programming tasks - the concept of APO was designed to solve a programmer's tasks. When normally you would need to think about how to ensure that a particular concern gets fulfilled every time in your codebase, you can think of this as simply an "aspect" of how you're programming, implement it in those terms directly, and count on your concerns to be implemented every time.
It requires less discipline, and you can focus on solving the practical programming tasks rather than trying to architect your way through high-level structural code requirements.
Might be worth 5 minutes of your time, anyway ;-)
Good luck!