symfony / polyfill

PHP polyfills

Home Page:https://symfony.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Function signature checking should be improved

zonuexe opened this issue · comments

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)

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