Incorrect encoding of special characters

Identify that when getting a $bean the special characters are incorrectly encoded. For example in an after_save hook to correct this I do the following

public function upsertContact(SugarBean $bean, string $event, $arguments): bool
{
// Decodes HTML entities in the first name and last name fields.
$bean->first_name = html_entity_decode($bean->first_name, ENT_QUOTES, 'UTF-8');
$bean->last_name = html_entity_decode($bean->last_name, ENT_QUOTES, 'UTF-8');
// ...
}

In mysql when checking SHOW VARIABLES LIKE 'character_set_database'; I get utf8mb4 same result when checking SHOW VARIABLES LIKE 'character_set_connection';

How can I fix this incorrect encoding of special characters throughout the application?

Thanks

Have you looked at $bean->fetched_row to see if it helps you get the clean data you need?

Hello. Thanks again. Indeed, using $bean->fetch_row I get the data encoded correctly. But if I am creating a record its value is false. Although curiously when creating a record the values โ€‹โ€‹of the fields first_name and last_name appear correctly. I attach a screenshot of the values โ€‹โ€‹of the $bean when creating and editing respectively.

This probably is a bug. Could you make a github issue so they can look into it and will see what they say.