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 adff758
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Feed.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace FeedWriter;

use \DateTime;
use DateTime;

/*
* Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
Expand Down 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 adff758

Please sign in to comment.