[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 18:50:12 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: | Focuses:
--------------------------+---------------------
Changes (by hellofromTonya):
* milestone: Awaiting Review => 6.6.1
Comment:
Hello @ambrosiawt,
Welcome to WordPress Core Trac. Thank you for reporting this issue.
[58335] introduced the `(string)` type casting change. It triggers when
the `WP_Comment` instance's `comment_ID` is not empty
([https://core.trac.wordpress.org/browser/tags/6.6/src/wp-includes
/comment-template.php#L27 see the code here]).
{{{
function get_comment_author( $comment_id = 0 ) {
$comment = get_comment( $comment_id );
$comment_id = ! empty( $comment->comment_ID ) ?
$comment->comment_ID : (string) $comment_id;
}}}
At first glance:
* I'm not seeing how the comment object's `comment_ID` property isn't
initialized (not empty) at this point.
* If the incoming `$comment_id` is an instance of `WP_Comment`, passing it
to `get_comment()` ''should'' also return the object.
* Thus, if it's an object and it has an ID, then it should fall into the
`?` branch.
So how and why is it falling into the `else` branch (i.e. running this
`(string) $comment_id`)?
Hmm.
Thinking the place to start is in understanding how, when, and why an
object passed into `get_comment()` may not have its `comment_ID` assigned
/ initialized.
Once that's understood, then the root cause may be elsewhere.
I'm pulling this into 6.6.1 milestone for awareness and investigation.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61681#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list