routes icon indicating copy to clipboard operation
routes copied to clipboard

PHP Warning: Creating default object from empty value

Open daronspence opened this issue 5 years ago • 4 comments

PHP version 7.2.29

Trace

wp-content/vendor/upstatement/routes/Routes.php:129
Routes::{closure}()
wp-includes/class-wp-hook.php:288
do_action('template_redirect')
wp-includes/template-loader.php:13

Looks like there is a reliance on this behavior. I'm not sure if it will be removed in a future version of PHP but there probably shouldn't be a reliance on it? 😄

Thoughts?

daronspence avatar Apr 14 '20 22:04 daronspence

@Daronspence I don't think I'm seeing what you're seeing. In master on 129 we've got: $query->is_attachment = false;. Is that what you're referring to?

jarednova avatar Apr 15 '20 15:04 jarednova

ahhhhh, wait a second!

	global $wp_query;
	$wp_query->is_404 = false;
	$query->is_attachment = false;
	$query->is_page = true;

Looks like those two calls to $query need to be rectified in some way. Is this something you'd be up for looking into more @Daronspence ?

jarednova avatar Apr 15 '20 15:04 jarednova

I can take a stab at it @jarednova but I'm not sure what the correct fix would be... maybe instantiating $query as a stdObject if it comes in as the default value?

Not sure tbh 🙁

daronspence avatar Apr 16 '20 01:04 daronspence

Just for a giggle, I swapped it from $query to $wp_query and that generated 200 warnings on the same page. Not good hah.

Since that $query variable is currently undefined in the function scope, those 2 lines could be removed without any effect that I can see. My IDE is complaining about it being undefined any way. I'll submit a PR for that, but will let you decide if that's the correct option.

daronspence avatar Apr 16 '20 01:04 daronspence