Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Monitor emits notices when 'file' and 'line' elements are not present in a stack trace #827

Open
siliconforks opened this issue Nov 4, 2023 · 1 comment · May be fixed by #828
Open

Comments

@siliconforks
Copy link

Consider the following shortcode:

function buggy_shortcode( $atts, $content, $shortcode_tag ) {
	throw new \Exception();
}

add_shortcode( 'buggy_shortcode', 'buggy_shortcode' );

If I visit a page with [buggy_shortcode], it will throw an exception and Query Monitor will display a stack trace, as expected, but if I look in the error log I see some additional notices (note that I have WP_DEBUG set to true):

PHP Notice:  Undefined index: file in .../query-monitor/collectors/php_errors.php on line 364
...
PHP Notice:  Undefined index: line in .../query-monitor/collectors/php_errors.php on line 364

If you look at the stack trace itself you can see the problem:

buggy_shortcode()
wp-includes/shortcodes.php:433

do_shortcode_tag()

preg_replace_callback()
wp-includes/shortcodes.php:273

do_shortcode()
wp-includes/class-wp-hook.php:310

...

Here do_shortcode() calls preg_replace_callback(), which calls do_shortcode_tag() as its callback. Therefore, do_shortcode_tag() is not being called from PHP code - it is being called from the PHP interpreter itself, so there is no .php file and line number. As a result, the stack trace is missing 'file' and 'line' elements.

This behavior does not appear to be explicitly documented anywhere, although it seems it is hinted at in https://www.php.net/manual/en/function.debug-backtrace.php where it says, "The possible [my emphasis] returned elements are as follows ... " - which suggests that the elements may or may not be present.

@johnbillion
Copy link
Owner

Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants