Make WordPress Core

Opened 3 years ago

Closed 6 months ago

#23428 closed defect (bug) (wontfix)

comments_open causes PHP notice in certain cases

Reported by: willnorris Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.5
Component: Comments Keywords: has-patch close
Focuses: Cc:


when comments_open() is called for a non-existant post (either a bad ID, or no ID passed and called from a non-single page), a PHP notice is caused. Ideally, plugins shouldn't be doing this, but a simple null check in comments_open() fixes the problem.

Attachments (1)

comment-template.diff (448 bytes) - added by willnorris 3 years ago.

Download all attachments as: .zip

Change History (6)

#1 @willnorris
3 years ago

oh, and the PHP Notice that is triggered is:

Notice: Trying to get property of non-object in .../wordpress/wp-includes/comment-template.php on line 776

#2 @SergeyBiryukov
3 years ago

  • Component changed from Comments to Warnings/Notices
  • Version changed from trunk to 2.5

pings_open() has the similar code (introduced in [6716]):

Seems like the notice is appropriate in the case if a non-existent post, not sure if we should hide it. Related: ticket:17299:6.

Last edited 3 years ago by SergeyBiryukov (previous) (diff)

#3 @markoheijnen
3 years ago

Maybe doing_it_wrong message?. A PHP notice isn't really telling something.

#4 @nacin
23 months ago

  • Component changed from Warnings/Notices to Comments

#5 @rachelbaker
6 months ago

  • Keywords close added
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Displaying a PHP Notice when the $post_id is invalid is expected behavior to me.

Note: See TracTickets for help on using tickets.