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

PHP 8.1: getid3_lib::mb_basename(): fix deprecation notice #335

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Aug 22, 2021

The getid3_lib::mb_basename() method calls the PHP native basename() function, the second parameter of which is the optional $suffix parameter which expects a string.

A parameter being optional, however, does not automatically make it nullable.

As of PHP 8.1, passing null to a non-nullable PHP native function will generate a deprecation notice.
In this case, this function call yielded a basename(): Passing null to parameter #2 ($suffix) of type string is deprecated notice.

Changing the null default value for the $suffix parameter to an empty string fixes this for most cases without BC-break.
Leaving the deprecation warning in place for when calls to the function would pass null for the $suffix so they can adjust their function call.

Refs:

The `getid3_lib::mb_basename()` method calls the PHP native `basename()` function, the second parameter of which is the _optional_ `$suffix` parameter which expects a `string`.

A parameter being optional, however, does not automatically make it nullable.

As of PHP 8.1, passing `null` to a non-nullable PHP native function will generate a deprecation notice.
In this case, this function call yielded a `basename(): Passing null to parameter JamesHeinrich#2 ($suffix) of type string is deprecated` notice.

Changing the `null` default value for the `$suffix` parameter to an empty string fixes this for _most_ cases without BC-break.
Leaving the deprecation warning in place for when calls to the function would pass `null` for the `$suffix` so they can adjust their function call.

Refs:
* https://www.php.net/manual/en/function.basename.php
* https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
@JamesHeinrich JamesHeinrich merged commit 5162e9f into JamesHeinrich:master Aug 23, 2021
@jrfnl jrfnl deleted the feature/php-8.1-fix-passing-null-to-non-nullable branch August 23, 2021 00:29
@StudioMaX StudioMaX mentioned this pull request Nov 28, 2021
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.

None yet

2 participants