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

Deprecated error when passing null to non-nullable argument for PHP 8.1 #252

Closed
jawira opened this issue Apr 22, 2021 · 5 comments
Closed
Labels
inconvenience Something that can be a bug but is more of an inconvenience than an actual bug v1.x

Comments

@jawira
Copy link

jawira commented Apr 22, 2021

Hi, this line is causing deprecated error when executed in PHP 8.1 (with GitHub Actions):

$this->content = new StringBasedFileContent(null);

The problem is the null value passed to substr function later. Example:

return (string) substr($this->content, $offset, $count);

Passing null to non-nullable arguments is deprecated since PHP 8.1.

Souce: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg

@allejo allejo changed the title Deprecated error when passing null to non-nullable argument Deprecated error when passing null to non-nullable argument for PHP 8.1 May 10, 2021
@allejo
Copy link
Member

allejo commented May 10, 2021

This has been fixed in our master branch already.

public function __construct(string $name, ?int $permissions = null)
{
$this->content = new StringBasedFileContent('');
$this->type = vfsStreamContent::TYPE_FILE;
parent::__construct($name, $permissions);
}

I've back ported the fix to the v1.x branch in 1483c50. We'll tag a new v1.6.x or 1.7.x release with this fix before or around PHP 8.1's release.

@allejo allejo closed this as completed May 10, 2021
@allejo allejo added inconvenience Something that can be a bug but is more of an inconvenience than an actual bug v1.x labels May 10, 2021
@alexpott
Copy link
Contributor

@allejo @jawira thanks for fixing the PHP 8.1 deprecation. Is there any chance of a 1.6.x or 1.7.x release sooner than PHP 8.1.x release with this fix in? This gives projects that are dependent on vfsStream a chance to work through all their PHP 8.1. deprecations prior to PHP 8.1's release. Thanks!

@allejo
Copy link
Member

allejo commented Jul 15, 2021

This gives projects that are dependent on vfsStream a chance to work through all their PHP 8.1. deprecations prior to PHP 8.1's release.

I hadn't thought about this! I'll tag a new release this week, just want to do some cleanup/organization first.

@allejo
Copy link
Member

allejo commented Jul 16, 2021

I've tagged v1.6.9 which includes this fix.

@alexpott
Copy link
Contributor

@allejo thanks for release! Nice one :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inconvenience Something that can be a bug but is more of an inconvenience than an actual bug v1.x
Projects
None yet
Development

No branches or pull requests

3 participants