30 November 2023
Sebastian
Find where a method was called in PHP
Methods that get called in a bunch of different places can be tricky to debug. For example, why is this model being saved?
In PHP, you can find the caller function or method using debug_backtrace()
.
Let's break this down:
-
debug_backtrace()
returns the full backtrace -
[1]
will return the previous location in the backtrace ([0]
would be the current location) -
function
will return the function or method at the location
Logging the caller in Ray
If you're using Ray, there's a caller
helper to save you some keystrokes and send it straight to Ray.
Running ray()->caller
will log the file, class, and method that was responsible for calling a method.
Understand and fix bugs faster
Ray is a desktop application that serves as the dedicated home for debugging output. Send, format and filter debug information from both local projects and remote servers.