If your show your error messages in HTML (with suitable safety using entities), this function won't work nicely because it uses newlines for formatting.
Here is a function that works similarly, but using <BR> tags. Insert it near the beginning of your program to add a stack to Warning output only, or modify it as you like:
// Here is code for error stack output in HTML:
function error_handler_callback($errno,$message,$file,$line,$context)
{
if ($errno === E_WARNING)
echo "Stack, innermost first:<br>".nl2br((new Exception())->getTraceAsString());
return false; // to execute the regular error handler
}
set_error_handler("error_handler_callback");