Let’s say I have a class loader I want to register.
$loader = new ClassLoader;
$loader->register();
When the method register() is called a second time, should I:
- Throw an exception stating that the class loader has already been registered
- Silently fail
- Return a boolean status
If I were to go with option #1, I would also provide a isRegistered() method offer the opportunity for some checking before it is called a second time.
What is the best way of handling this scenario?
Are there any other, better options?
Have you considered something like triggering a warning or a notice?
Unlike exceptions, triggering errors is a good way to find flaws/disruptions in code without halting the execution of the program. You keep the backtrace and a get an entry in the error log. If a mistake like this (registering a class loader twice) goes on production, you’d want it to be transparent for the user (it’s not critical), but with the programmer getting notified.