Answer the question
In order to leave comments, you need to log in
Is it possible to forbid creating an object in the constructor of this object (php)?
It's a stupid question, but still. Is it possible to forbid creating an object in the constructor of this object (php)? That is, how to ban? Whether in sense the object can destroy itself in the constructor.
Answer the question
In order to leave comments, you need to log in
It is generally impossible to forbid creating an instance of a class (if the class is not abstract), you can prohibit creating an instance from the outside by making the constructor private (private), but you can still create it in the class itself. Of course, you can throw an exception, but I did not check what will be the result of new.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question