[wp-trac] [WordPress Trac] #61681: PHP Fatal error: Uncaught Error: Object of class WP_Comment could not be converted to string

WordPress Trac noreply at wordpress.org
Wed Jul 17 21:15:31 UTC 2024


#61681: PHP Fatal error:  Uncaught Error: Object of class WP_Comment could not be
converted to string
--------------------------------------+---------------------
 Reporter:  ambrosiawt                |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  6.6.1
Component:  Comments                  |     Version:  6.6
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+---------------------

Comment (by hellofromTonya):

 Patch: https://github.com/WordPress/wordpress-develop/pull/7053

 This patch:

 1. First adds tests to show the fatal error happening in
 `get_comment_author()` when the incoming `WP_Comment` object does not have
 a comment ID (for whatever reason) or that property is empty.
 2. Second adds the fix, which (a) defensively guards the string type
 casting `(string) $comment_id` for when `$comment_id` is scalar and (b) if
 neither path is true, sets it an empty string as a default.

 The `$comment_id` is not used for getting the comment author; rather it
 was added to pass to the filter.

 This patch fixes the fatal error. But what is passed to the filter would
 no longer be an object. I don't think it's a BC break in that the
 `$comment_id` passing in the filter is documented to a `string` data type,
 not an instance of `WP_Comment`.

 @ambrosiawt are you able to test the patch to see if resolves the issue?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61681#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list