[wp-trac] [WordPress Trac] #56244: Use a consistent parameter name for functions accepting a comment ID or object

WordPress Trac noreply at wordpress.org
Mon Jul 18 20:45:40 UTC 2022

#56244: Use a consistent parameter name for functions accepting a comment ID or
 Reporter:  SergeyBiryukov  |       Owner:  SergeyBiryukov
     Type:  enhancement     |      Status:  accepted
 Priority:  normal          |   Milestone:  6.1
Component:  Comments        |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  2nd-opinion     |     Focuses:  docs, coding-standards

Comment (by SergeyBiryukov):

 Replying to [comment:2 audrasjb]:
 > shouldn't we keep `$comment_id` so it's more clear than just `$comment`?
 > In my –very humble ^^– opinion, `$comment` would be reserved for
 `WP_Comment` object, just like `$post` and `$post_id`. What do you think?

 Thanks for the comment! To me, it's confusing when `$comment_id` can mean
 two different things:
 * A comment ID.
 * A comment object.

 I would like to separate these, so that:
  * `$comment_id` always means a (numeric) comment ID.
  * `$comment` as a function parameter means either a comment ID or comment
 object, but is typically converted to an object within the first lines of
 the function.

 This is already the case for the majority of the functions, and is
 consistent with the majority of post functions with a `$post` parameter
 that accept a post ID or post object (as noted in #56243).

 This ticket aims to bring some consistency to the remaining functions :)

 This is also relevant in the context of PHP 8 named parameters, which
 WordPress does not support right now, but should eventually, and by that
 time renaming any parameters would be a backward compatibility break, so
 I'm trying to clean this up while we still can :)

Ticket URL: <https://core.trac.wordpress.org/ticket/56244#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list