mk-j / PHP_XLSXWriter

Lightweight XLSX Excel Spreadsheet Writer in PHP
MIT License
1.84k stars 665 forks source link

PHP 8.1 Support Issue - Passing null pararmeter deprecated #324

Closed zadro closed 1 year ago

zadro commented 2 years ago

Please see error below:


Severity: 8192

Message: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated

Filename: php_xlsxwriter/xlsxwriter.class.php

Line Number: 760

Adding ternary to line 760 is a suggested fix:

return strtr(htmlspecialchars($val ?: '', ENT_QUOTES | ENT_XML1), $badchars, $goodchars);//strtr appears to be faster than str_replace

LDAV commented 2 years ago

... or completely avoid processing string, adding if(!$val) return ""; at line 757

lubos-h commented 1 year ago

How about declaring the value as string? return strtr(htmlspecialchars((string)$val, ENT_QUOTES | ENT_XML1), $badchars, $goodchars);//strtr appears to be faster than str_replace

w263756314 commented 1 year ago

success

mk-j commented 1 year ago

fixed with (string)$val in a recent commit