Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#21337 closed defect (bug) (fixed)

COMMENTS_TEMPLATE: cannot define a constant twice in PHP

Reported by: kitchin's profile kitchin Owned by: ryan's profile ryan
Milestone: 3.5 Priority: normal
Severity: trivial Version: 3.4.1
Component: Comments Keywords: commit
Focuses: Cc:


A minor PHP issue in wp-includes/comment-template.php in comments_template() :

	define('COMMENTS_TEMPLATE', true);

PHP does not allow constants to be re-defined, so the clause "!COMMENTS_TEMPLATE" can have no effect other than raise a warning.

The patch removes the clause.

Normally this warning would happen if comments_template() is called twice by the theme, but the subsequent require() statement would raise an error anyway.

In one edge case it might not raise an error:

  1. Theme calls comments_template()
  2. Theme calls comments_template() again with a different parameter or after a different filter is in effect.

So the patch loses a warning in that case.

I grepped the codebase and did not find any similar clause before a define().

The conditional code around the define() was added in this changeset:

Attachments (1)

comments-define-bug.diff (487 bytes) - added by kitchin 12 years ago.

Download all attachments as: .zip

Change History (4)

#1 @scribu
12 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 3.5

Agreed, the code decides to define a constant based on it's value, which makes 0 sense.

#2 @nacin
12 years ago

What's the point of COMMENTS_TEMPLATE, anyway? Seems like it could disappear. Are people relying on it to detect something within a template?

#3 @ryan
12 years ago

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

In [21330]:

Don't attempt to define the COMMENTS_TEMPLATE constant twice. Props kitchin. fixes #21337

Note: See TracTickets for help on using tickets.