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

ENH PHP 8.1 compatibility #53

Merged
merged 1 commit into from
Apr 22, 2022

Conversation

emteknetnz
Copy link
Member

@emteknetnz emteknetnz marked this pull request as ready for review April 20, 2022 05:08
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The outstanding question in other PRs about file_put_contents() will also affect this PR.

Comment on lines +142 to +143
$b = preg_replace($this->filterPattern ?? '', '', $second ?? '');
return preg_replace($this->filterPattern ?? '', '', $first ?? '') === $b;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$b = preg_replace($this->filterPattern ?? '', '', $second ?? '');
return preg_replace($this->filterPattern ?? '', '', $first ?? '') === $b;
$b = preg_replace($this->filterPattern ?? '//', '', $second ?? '');
return preg_replace($this->filterPattern ?? '//', '', $first ?? '') === $b;

Passing an empty string instead of an empty regex results in a different warning being emitted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear what the reasoning was for assigning the $b variable like that but it doesn't really affect anything so I'm fine with it. I'm guessing it was a phpcs issue with too many characters on one line, maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per comments on another similar PR - the warning that gets emitted for the empty string is correct and points at the issue which already exists with the null value. This is only about resolving the deprecation warning emitted by passing null.

@@ -42,7 +42,7 @@ public function testInvalidFileExtensionValidatingMimeType()
$this->assertFalse($result, 'Load failed because file extension does not match excepted MIME type');
$this->assertEquals('File is not a valid upload', $errors[0]);

unlink($tmpFilePath);
unlink($tmpFilePath ?? '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will emit a warning whether it's null or an empty string:

[Warning]: unlink(): No such file or directory

Does it also get a deprecation warning emitted when it's null?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that this does emit a deprecation warning as well as the error if the value passed in is null.

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For posterity: See discussion in silverstripe/silverstripe-admin#1294 about the general approach. tl;dr:

the purposes of this PR is to avoid passing null (specifically null) from built-in functions that as of php 8.1 will throw deprecation warnings if null is passed in. The approach is necessarily heavy-handed, and while there are many situations where it isn't needed, it would be prohibitively laborious to find all of those situations by hand.

Looks good to me

@GuySartorelli GuySartorelli merged commit 994cabf into silverstripe:2 Apr 22, 2022
@GuySartorelli GuySartorelli deleted the pulls/2/php81 branch April 22, 2022 04:19
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