I would like to ask if this is possible:
I have a class with a private constructor which of course throws a fatal error if I try to instantiate that class from an invalid context (outside the class), can I catch this fatal error and the name of the class and then throw an exception like:
// catch the private constructor from invalid context fatal error
// and store somehow the name of the class inside $class
// and then:
throw new UninstantiableClassException("The class " . $class . " cannot be instantiated");
Is that possible, or basing on this post I have just found it's not? -> PHP : Custom error handler - handling parse & fatal errors
If it is not possible, should I make the constructor public and then throw and exception inside of it like this?:
public function __construct() {
throw new UninstantiableClassException("The class " . get_class($this) . " cannot be instantiated");
}