I am having some issues on a large-ish project, and it boils down to a particular class is somehow being instantiated multiple times, which is causing un-needed replication / overheads.
Is there any way to find out automatically what file / line number it is being instantiated from?
I have seen this question here - Find where a class was instantiated but I am not getting a fatal error for it being redeclared so I dont think include / require is the problem.
in the constructor I have got it to output to a txt file with timestamp, just need to know where the offending code is and remove / streamline it
PHP | get_class() Function Return Value: This function returns the class name of which object is an instance. It returns FALSE if the object is not an object. If the object is omitted when inside the class then the class name is returned. $obj = new GFG();
SomeClass::class will return the fully qualified name of SomeClass including the namespace. This feature was implemented in PHP 5.5. It's very useful for 2 reasons. You can use the use keyword to resolve your class and you don't need to write the full class name.
The instanceof keyword is used to check if an object belongs to a class. The comparison returns true if the object is an instance of the class, it returns false if it is not.
debug_backtrace() will give the whole shebang what happened. get_class($this) will give the top child class if you need just that.
Call in your constructor debug_backtrace
or debug_print_backtrace
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With