Opened 17 months ago

Last modified 13 months ago

#19706 new defect (bug)

NOTICE: wp-admin/includes/post.php:834 - Illegal member variable name

Reported by: markjaquith Owned by:
Priority: low Milestone: Awaiting Review
Component: Warnings/Notices Version: 3.3
Severity: normal Keywords: close
Cc: mp3j3rk

Description

Received this notice:

NOTICE: wp-admin/includes/post.php:834 - Illegal member variable name

Traced it to this in wp_count_posts():

	$count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );

	$stats = array();
	foreach ( get_post_stati() as $state )
		$stats[$state] = 0;

	foreach ( (array) $count as $row )
		$stats[$row['post_status']] = $row['num_posts'];

	$stats = (object) $stats;

Apparently I have a post with a post status of a blank string. So that gets set to an array key, and then is cast to an object. WP doesn't like that.

Proposed:

	foreach ( (array) $count as $row ) {
		if ( !empty( $row['post_status'] ) )
			$stats[$row['post_status']] = $row['num_posts'];
	}

Just discard empty post_status rows.

Change History (3)

Isn't the real bug that somehow you managed to get a post with an empty post_status? According to the phpdoc for get_post_statuses(), posts have a limited set of valid status values (and empty isn't one of them).

  • Cc mp3j3rk added

This should be aimed at the code that saves a post to the DB then, and why it would have placed an empty value in wp_posts.post_status without having thrown an error.

I need a pet project, I think I'll give this one a look-see.

@markjaquith What steps did you take to produce the notice, and can you confirm any out of the ordinary circumstances when you published that post?

Last edited 15 months ago by mp3j3rk (previous) (diff)
  • Keywords close added
  • Milestone changed from 3.4 to Awaiting Review

wp_insert_post() sets the post_status to 'draft' if it is empty. I don't think this was caused by core and is probably not something we should "fix" as it points to a developer issue. (Additionally, I doubt this is the only area in core that breaks due to this, whether or not it throws a notice.)

Note: See TracTickets for help on using tickets.