Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#12997 closed defect (bug) (fixed)

Call to a member function get_names() on a non-object in user.php

Reported by: ipstenu Owned by:
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: General Keywords:
Focuses: Cc:


This is showing up in my error.log on both 3.0 installes:

PHP Fatal error: Call to a member function get_names() on a non-object in /home/ipstenu/public_html/wp-includes/user.php on line 422

solarissmoke (on the wp.org forums) did more research and came up with this:

Hi folks,

I'm getting this error when wordpress does cron jobs (by visiting wp-cron.php?doing_wp_cron):

PHP Fatal error: Call to a member function get_names() on a non-object in /wp-includes/user.php on line 422

I think that the function where the error occurs (count_users()) is being called by the wp_version_check function which is one of the regular cron actions. The error suggests that the global variable $wp_roles has not been created by the time the function is called - but I can't track where this should be happening in the first place.

I've looked at my cron options and the only ones there are the defaults (wp_update_plugins, wp_version_check, wp_update_themes, wp_scheduled_delete).

The error is occurring every single time wp-cron.php is accessed.

See: http://wordpress.org/support/topic/387647

I can repro it as well.

Attachments (1)

12997.diff (2.1 KB) - added by ryan 12 years ago.

Download all attachments as: .zip

Change History (9)

#1 @ryan
12 years ago

  • Milestone changed from Unassigned to 3.0

#2 @ryan
12 years ago

$wp_roles is created on the fly when certain functions in capabilities.php are called. When there is no current user, such as in the case of cron events, $wp_roles does not get created. Thus the error now that count_users() is accessing $wp_roles. I think we can move instantiation of $wp_roles to wp-settings.php along with the other global object instances.

12 years ago

#3 @ryan
12 years ago

As discussed with nacin, the cost this adds is the memory overhead of having $wp_roles instantiated for page view for non-logged in users, which is most visitors to the site. It is currently instantiated only for logged in users. If we want to avoid this overhead, we can either check if the object isset in count_users() and set it if not or move all of the isset checks into an _wp_roles_get_object() style function and call that function in count_users().

#4 @solarissmoke
12 years ago

The count_users() function has two "strategies", and the second strategy ('memory') doesn't use$wp_roles as it just queries the database directly. (However there are apparently other issues: []

Perhaps an alternative solution is to get wp_version_check() to call count_users('memory')? This would avoid the need to have $wp_roles instantiated for all non-logged in users.

#5 @solarissmoke
12 years ago

Never mind my suggestion - it looks like memory issues might be a problem which is why the former strategy is used in the first place.

#6 @ryan
12 years ago


I went for a least change/least impact fix for now.

#7 @ipstenu
12 years ago

I put this diff in on the 16th, and I've not seen the error since, so ... Looks good!

#8 @nacin
12 years ago

  • Resolution set to fixed
  • Status changed from new to closed

I'm going to close this as fixed. Least impact seems fine.

Note: See TracTickets for help on using tickets.