Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast $string to string if not string(ex:null) in filterInvalidXMLChars(). #46

Conversation

uzulla
Copy link

@uzulla uzulla commented Jan 1, 2022

Hi.

I got a ignore-able tiny error with PHP>=8.1

  • PHP>=8.1 trigger deprecation error in some old code.
  • Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /work/Feed.php on line 687

ex code

// Add some line to sample code.

$nullable_value = null;
$TestFeed->setChannelElement('description', $nullable_value);

// ... SNIP ... 

$TestFeed->generateFeed(); // error.

error output.

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /work/Feed.php on line 687
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /work/Feed.php on line 1015
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /work/Feed.php on line 687
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /work/Feed.php on line 1015
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /work/Feed.php on line 687
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /work/Feed.php on line 1015
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /work/Feed.php on line 687
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /work/Feed.php on line 1015

Of course, $TestFeed->setChannelElement('something', NULL) is absolutly wrong. but many php are still using NULL as blank strings.
It save some codes if cast NULL to string here.

thanks.

- 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`
@mibe
Copy link
Owner

mibe commented May 24, 2023

You are correct, passing NULL is absolutly wrong. The latest version throws an exception in such cases.
Thanks for noticing!

@mibe mibe closed this May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants