PHPOffice/PHPWord

Problem with setValue function in TemplateProcessor

xlh2046 opened this issue · 0 comments

Describe the bug and add attachments

When using the setValue function of the Template Processor class:
$templateProcessor->setValue('score', '0');

Expected behavior

I want to replace the score variable with 0,but the result was that the score variable was replaced with ''.
After checking the code, this function looks like this:
/**
* @param ?string $subject
*
* @return string
*/
protected static function ensureUtf8Encoded($subject)
{
return $subject ? Text::toUTF8($subject) : '';
}

I will change it as follows, local testing is possible. like this:
protected static function ensureUtf8Encoded($subject)
{
$subject = $subject??'';
return $subject ? Text::toUTF8($subject) : $subject;
}

Steps to reproduce

setValue('score', '0'); ... ### PHPWord version(s) where the bug happened 1.3.0 ### PHP version(s) where the bug happened 8.3 ### Priority - [ ] I want to crowdfund the bug fix (with [@algora-io](https://docs.algora.io/bounties/overview)) and fund a community developer. - [ ] I want to pay the bug fix and fund a maintainer for that. (Contact @Progi1984)