Skip to content

Commit

Permalink
Some old code uses a NULL(or other) as a blank string. cast to string.
Browse files Browse the repository at this point in the history
- PHP>=8.1 trigger deprecation error with no manner code.
- `preg_replace(): Passing null to parameter mibe#3 ($subject) of type array|string is deprecated`
  • Loading branch information
uzulla committed Jan 1, 2022
1 parent d9f4838 commit 6c667a0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ public static function uuid($key = null, $prefix = '')
*/
public static function filterInvalidXMLChars($string, $replacement = '_') // default to '\x{FFFD}' ???
{
// Convert $string to string if not string (ex:NULL).
// Avoid `preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated` error from PHP>=8.1.
if (!is_string($string))
$string = (string)$string;

$result = preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]+/u', $replacement, $string);

// Did the PCRE replace failed because of bad UTF-8 data?
Expand Down

0 comments on commit 6c667a0

Please sign in to comment.