Skip to content

Commit

Permalink
PHP 8.1: fix "passing null to non-nullable" deprecation notice
Browse files Browse the repository at this point in the history
As of PHP 8.1, passing `null` to non-nullable arguments of PHP native functions is deprecated.
Ref: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg

The `SimplePie_Enclosure::get_extension()` returns the file extension as a string or `null`.

In the `SimplePie_Enclosure::get_real_type()` method, the return value of a call to the `get_extension()` method was directly passed on to the PHP native `strtolower()` function, leading to the PHP 8.1 `strtolower(): Passing null to parameter simplepie#1 ($string) of type string is deprecated` deprecation notice.

This small change fixes this issue without BC break.

This is covered by 36 of the existing tests in the `OldTest` class.
  • Loading branch information
jrfnl committed Aug 10, 2021
1 parent ebba0a8 commit 08ee8ce
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/SimplePie/Enclosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,11 @@ public function get_real_type($find_handler = false)
// If we encounter an unsupported mime-type, check the file extension and guess intelligently.
if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
{
$extension = $this->get_extension();
if ($extension === null) {
return null;
}

switch (strtolower($this->get_extension()))
{
// Audio mime-types
Expand Down

0 comments on commit 08ee8ce

Please sign in to comment.