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

Function signature checking should be improved #473

Open
zonuexe opened this issue Mar 31, 2024 · 1 comment
Open

Function signature checking should be improved #473

zonuexe opened this issue Mar 31, 2024 · 1 comment

Comments

@zonuexe
Copy link
Contributor

zonuexe commented Mar 31, 2024

These errors below looks strange:

40) Warning
Incompatible signature for PHP >= 8:
- mb_ucfirst(string $string, ?string $encoding = null): string
+ mb_ucfirst(string $string, ?string $encoding = null): string

41) Warning
Incompatible signature for PHP >= 8:
- mb_lcfirst(string $string, ?string $encoding = null): string
+ mb_lcfirst(string $string, ?string $encoding = null): string

Internal functions up to PHP 8.0 implicitly accepted null as a string. It seems that the type is declared as ?string instead of string for compatibility in polyfills up to php80.

$map = [
'?' => '',
'IDNA_DEFAULT' => \PHP_VERSION_ID >= 80100 ? 'IDNA_DEFAULT' : '0',
'array|string|null $string' => 'array|string $string',
'array|string|null $from_encoding = null' => 'array|string|null $from_encoding = null',
'array|string|null $from_encoding' => 'array|string $from_encoding',
];
if (strtr($polyfillSignature, $map) !== $originalSignature) {
$warnings[] = TestListener::warning("Incompatible signature for PHP >= 8:\n- {$f['name']}$originalSignature\n+ {$f['name']}$polyfillSignature");
}

In the code below, ? is removed to check the difference between the internal function and the polyfill interface.

PHP 8.4 deprecates implicit nullable, so this test should be replaced with more stringent checks.

refs #471 (comment)

@stof
Copy link
Member

stof commented Apr 1, 2024

The implicit null in internal functions actually exists until PHP 9.0. It is deprecated in PHP 8.1 but it still works.

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

No branches or pull requests

2 participants