[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
Thu Jul 18 15:08:18 UTC 2024
#61681: PHP Fatal error: Uncaught Error: Object of class WP_Comment could not be
converted to string
---------------------------------------------+-----------------------------
Reporter: ambrosiawt | Owner: hellofromTonya
Type: defect (bug) | Status: closed
Priority: high | Milestone: 6.6.1
Component: Comments | Version: 6.6
Severity: normal | Resolution: fixed
Keywords: has-patch has-unit-tests commit | Focuses:
---------------------------------------------+-----------------------------
Changes (by hellofromTonya):
* status: reviewing => closed
* resolution: => fixed
Comment:
In [changeset:"58755" 58755]:
{{{
#!CommitTicketReference repository="" revision="58755"
Comments: Fix fatal error when get_comment_author() receives an object
with no comment_id.
[58335] introduced `(string)` type casting of the passed in `$comment_id`
value. If `$comment_id` is a scalar, it works as expected. But if it's an
`object`, the following fatal error is thrown:
{{{
Object of class WP_Comment could not be converted to string
}}}
This fatal error happens when the incoming `$comment_id` is an instance of
`WP_Comment` (or any object) without a `comment_ID` (empty).
This changeset adds tests to demonstrate the fatal error and validate the
fix.
It fixes the fatal error by restructuring the ternary checks into an
`if/elseif/else` structure for the 3 paths:
- When `$comment->comment_ID` is not empty, then it uses the property.
- When `$comment_id` is scalar, then it type casts it to a `string`.
- Else, the default is an empty `string`.
Follow-up to [58335], [41127], [52818].
Props ambrosiawt, hellofromTonya, jorbin, mukesh27, SergeyBiryukov.
Fixes #61681.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61681#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list