Is it possible to know in which file the object is being initialized?
For example, I want to prevent the class from running if it’s in X file. I know it defeats the purpose of being re-usable, etc etc. I don’t know if it’s possible in PHP or possible at all.
In your constructor, examine the result of
debug_backtrace(). The first frame describes the function (a file and line number) of the constructor itself, whereas the next frame describes the code that called the constructor.This works anywhere, not just within functions or methods.