-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix PHP 8.1 compatibility issues #374
Conversation
@schlessera I've followed the suggestion by swissspidy. But still having some tests failure related to the encoding in Please suggest how should I proceed. |
Related upstream issue: https://bugs.php.net/bug.php?id=81390 It seems like the algorithm for detecting the encoding has changed in PHP 8.1. The best approach right now seems to drastically limit the list of available encodings to more closely match was PHP 8.0 and lower was doing. In the above issue, something like this is suggested: $encodings = ['UTF-8', 'SJIS', 'GB2312',
'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4',
'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9',
'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16',
'WINDOWS-1252', 'WINDOWS-1251', 'EUC-JP', 'EUC-TW', 'KOI8-R', 'BIG-5',
'ISO-2022-KR', 'ISO-2022-JP', 'UTF-16'
]; However, this encoding order might cause regressions in PHP 8.0 and lower, so we'll have to check for that and maybe even split the encoding order here by PHP version. |
// Make sure $value is always a string and not null. | ||
$value = $value ? $value : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone passes null
, shouldn't PHP yell at them for it? Converting null
to empty string here would hide any potential issues in consumer code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested this scenario with following code snippet and found out that if we pass null as the function argument, then $value will be Null not an empty string,
<?php
function test($a, $b = '')
{
var_dump($a);
var_dump($b); // $b is Null for second function call.
}
test('without b');
test('with null', null);
@schlessera I've updated the existing encoding order. Looks like I did some mistake when I tried to change that order before. But it is working now for all tests. FYI the suggested encoding array does not work. PHP 8.1 produces different result than its lower versions. |
As discussed during our meeting, this needs many more test cases covering as many different encodings as possible, to ensure we consistently have the same behavior between PHP 8.1 and PHP 8.0 and lower. |
@ediamin Note that the files in the |
@schlessera I've updated the code with some new test cases. As you suggested earlier, I had to use a separate order list for PHP 8.1. |
da85c47
to
c802630
Compare
@schlessera I've updated the code and added the ReturnTypeWillChange in validator source files. |
The goal of this PR is to fix some error and warning notices when run in the PHP 8.1.
Fixes #362