Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#27117 closed defect (bug) (invalid)

Fatal error in url_to_postid() when $wp_rewrite is null

Reported by: chrishoward's profile chrishoward Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.1
Component: Rewrite Rules Keywords:
Focuses: Cc:

Description

Encountered a fatal error today:

Fatal error: Call to a member function wp_rewrite_rules() on a non-object in /Users/chrishoward/Dropbox/wp-mba.dev/wp-includes/rewrite.php on line 301

Did some testing, and $wp_rewrite was null.

Line 301 is:

$rewrite = $wp_rewrite->wp_rewrite_rules();

Changed it to:

$rewrite = !empty($wp_rewrite)?$wp_rewrite->wp_rewrite_rules():false;

and things seem to work.

Not sure if the true problem is the 3rd party plugin that called this function, or WP, but I do think there should be some sort of protection in WP from getting a fatal error in this rare circumstance.

Change History (3)

#1 @nacin
11 years ago

Hi chrishoward, thanks for the report.

url_to_postid() requires WP_Rewrite, which means it can't be called before the 'init' hook.

Since this error has always been there, we prefer to keep errors in this case. It tells developers that they are doing something wrong. If we attempt to suppress this, it will be much harder to debug and doesn't do anyone good.

#2 follow-up: @chrishoward
11 years ago

Thanks, Andrew, for the quick reply.

Makes sense - but dang! Was hoping I'd found a real bug. :/

I'll contact the plugin dev then.

#3 in reply to: ↑ 2 @nacin
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Replying to chrishoward:

Makes sense - but dang! Was hoping I'd found a real bug. :/

Not to worry, eventually you'll get to the point where you'll see them all the time! Follow http://make.wordpress.org/core/ and you'll find a lot of ongoing things to test and find bugs in.

Note: See TracTickets for help on using tickets.