Skip to content

Updating to PHP 8.1 causes a "PHP Deprecated" message to show up #27

Description

@wahabmirjan

I use Normalizer in my code, and after updating to PHP 8.1, I started getting this message

[16-Nov-2022 16:24:31 UTC] PHP Deprecated: Automatic conversion of false to array is deprecated in /var/www/dev-server/wp-content/plugins/my-plugin/vendors/url-normalizer/Normalizer.php on line 375

After further investigating, it seems that the issue is in the mbParseUrl($url) function. PHP 8.1 now does not like the following:

$result = false;
/// some code here
$result[$key] = urldecode(str_replace($replacements, $entities, $value));
/// some more code
return $result;

In other words, you cannot implicitly convert a boolean to an array. So here is a suggested solution

$result = [];
/// some code here
$result[$key] = urldecode(str_replace($replacements, $entities, $value));
/// some more code
return (empty($result)) ? false : $result;

This is obviously one solution. Another solution is:

$result = false;
/// some code here
if(!is_array($result)) $result = [];
$result[$key] = urldecode(str_replace($replacements, $entities, $value));
/// some more code
return $result;

Anyways, those are suggested solutions. Thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions