Symfony polyfill not found
Bug Report
| Subject | Details |
|---|---|
| Rector version | 1.1.1 |
mb_ucfirst() from symfony/polyfill-php84 is not found by rector.
I tried some ways to work around the issue, without success:
- adding it to explicit autoload in rector config
- using with the new
withPhpPolyfill() - using
withSets([LevelSetList::UP_TO_PHP_83])instead ofwithPhpSets()
Minimal PHP Code Causing Issue
$ composer require symfony/polyfill-php84 v1.30.0
src/test.php:
<?php declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
# Test that the polyfill is correctly loaded
print mb_ucfirst('hello') . PHP_EOL;
rector.php:
<?php declare(strict_types=1);
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withPaths([__DIR__ . '/src'])
->withPhpSets(php83: true);
What's happening?
$ php src/test.php
Hello
$ vendor/bin/rector
[ERROR] Could not process "src/test.php" file, due to:
"Call to undefined method Symfony\Polyfill\Mbstring\Mbstring::mb_ucfirst()". On line: 207
Expected Behaviour
I'm not sure which rule is in effect here? I guess nothing should happen...
The error seems from phpstan:
➜ test-php84 vendor/bin/rector process src -vvv
[ERROR] Could not process "/Users/samsonasik/test-php84/src/test.php" file, due to:
"System error: "Call to undefined method Symfony\Polyfill\Mbstring\Mbstring::mb_ucfirst()"
Stack trace:
#0 phar://vendor/phpstan/phpstan/phpstan.phar/src/Type/Php/StrCaseFunctionsReturnTypeExtension.php(79):
mb_ucfirst('hello')
it seems some autoload is overlapped
The error seems still happen even mb_ucfirst is not called:
Oh, I edit the wrong file, when mb_ucfirst not called, it working ok
➜ test-php84 vendor/bin/rector process src/test.php --dry-run
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
[OK] Rector is done!
I guess the patch needs to be in phpstan-src itself, as it got error on phpstan.org
https://phpstan.org/r/4aa0a8d2-809b-472b-a406-6d085b4781aa
and stack trace shown on phpstan:
[ERROR] Could not process "src/test.php" file, due to:
"System error: "Call to undefined method Symfony\Polyfill\Mbstring\Mbstring::mb_ucfirst()"
Stack trace:
#0 phar://vendor/phpstan/phpstan/phpstan.phar/src/Type/Php/StrCaseFunctionsReturnTypeExtension.php(79):
mb_ucfirst('hello')
#1 phar://vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1638):
PHPStan\Type\Php\StrCaseFunctionsReturnTypeExtension->getTypeFromFunctionCall(Object(PHPStan\Reflection\Php\Ph
pFunctionReflection), Object(PhpParser\Node\Expr\FuncCall), Object(PHPStan\Analyser\MutatingScope))
Yeah, you need the symfony/polyfill-php84 package to be installed first, with it, phpstan does find the symbols, but rector doesn't
Same errors, A quick fix that worked for me
-"symfony/polyfill-mbstring": "1.30",
+"symfony/polyfill-mbstring": "1.29",
Fixed by upgrading phpstan from 1.11.5 to 1.11.6 ... kind of.
Now phpstan doesn't report error if polyfill is actually missing, and undefined function mb_ucfirst() is not found.