Upstatement / routes

Simple routing for WordPress
188 stars 38 forks source link

PHP Warning: Creating default object from empty value #22

Closed daronspence closed 1 year ago

daronspence commented 4 years ago

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?

jarednova commented 4 years ago

@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 commented 4 years ago

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 ?

daronspence commented 4 years ago

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 commented 4 years ago

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.