Home > Back-end >  Symfony update 5.4 to 6.1
Symfony update 5.4 to 6.1

Time:08-01

I update symfony version 5.4 to 6.1, I have this error and I can't find the solution on the forum (I think that there are several problems in same time):

Fatal error: Declaration of App\Repository\UserRepository::upgradePassword(Symfony\Component\Security\Core\User\UserInterface $user, string $newEncodedPassword): void must be compatible with Symfony\Component\Security\Core\User\PasswordUpgraderInterface::upgradePassword(Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void in /Users/pjf/sites/myapp/src/Repository/UserRepository.php on line 29

In my app:

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 7.4.30. in /Users/pfjsites/myapp/vendor/composer/platform_check.php on line 24

My file composer.json:

{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
    "php": ">=8.1",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "composer/package-versions-deprecated": "1.11.99.3",
    "doctrine/annotations": "^1.0",
    "doctrine/doctrine-bundle": "^2.4",
    "doctrine/doctrine-migrations-bundle": "^3.0",
    "doctrine/orm": "^2.9",
    "dompdf/dompdf": "^1.2",
    "easycorp/easyadmin-bundle": "^4.0",
    "knplabs/knp-paginator-bundle": "^5.8",
    "phpdocumentor/reflection-docblock": "^5.2",
    "sensio/framework-extra-bundle": "^6.2",
    "symfony/asset": "6.1.*",
    "symfony/console": "6.1.*",
    "symfony/dotenv": "6.1.*",
    "symfony/expression-language": "6.1.*",
    "symfony/flex": "^1.3.1",
    "symfony/form": "6.1.*",
    "symfony/framework-bundle": "6.1.*",
    "symfony/http-client": "6.1.*",
    "symfony/intl": "6.1.*",
    "symfony/mailer": "6.1.*",
    "symfony/mime": "6.1.*",
    "symfony/monolog-bundle": "^3.1",
    "symfony/notifier": "6.1.*",
    "symfony/process": "6.1.*",
    "symfony/property-access": "6.1.*",
    "symfony/property-info": "6.1.*",
    "symfony/proxy-manager-bridge": "6.1.*",
    "symfony/runtime": "6.1.*",
    "symfony/security-bundle": "6.1.*",
    "symfony/serializer": "6.1.*",
    "symfony/string": "6.1.*",
    "symfony/translation": "6.1.*",
    "symfony/twig-bundle": "6.1.*",
    "symfony/validator": "6.1.*",
    "symfony/web-link": "6.1.*",
    "symfony/yaml": "6.1.*",
    "twbs/bootstrap-icons": "^1.9",
    "twig/extra-bundle": "^2.12|^3.0",
    "twig/intl-extra": "^3.3",
    "twig/twig": "^2.12|^3.0"
},
"require-dev": {
    "doctrine/doctrine-fixtures-bundle": "^3.4",
    "phpunit/phpunit": "^9.5",
    "symfony/browser-kit": "6.1.*",
    "symfony/css-selector": "6.1.*",
    "symfony/debug-bundle": "6.1.*",
    "symfony/maker-bundle": "^1.36",
    "symfony/phpunit-bridge": "^5.3",
    "symfony/stopwatch": "6.1.*",
    "symfony/web-profiler-bundle": "6.1.*"
},
"config": {
    "optimize-autoloader": true,
    "preferred-install": {
        "*": "dist"
    },
    "sort-packages": true,

    "platform-check": false

},
"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},
"autoload-dev": {
    "psr-4": {
        "App\\Tests\\": "tests/"
    }
},
"replace": {
    "symfony/polyfill-ctype": "*",
    "symfony/polyfill-iconv": "*",
    "symfony/polyfill-php72": "*"
},
"scripts": {
    "auto-scripts": {
        "cache:clear": "symfony-cmd",
        "assets:install %PUBLIC_DIR%": "symfony-cmd"
    },
    "post-install-cmd": [
        "@auto-scripts"
    ],
    "post-update-cmd": [
        "@auto-scripts"
    ]
},
"conflict": {
    "symfony/symfony": "*"
},
"extra": {
    "symfony": {
        "allow-contrib": false,
        "require": "6.1.*"
    }
},

"platform": {
 "php": "8.1.6"}}}

I add some code (Symfony 5.4.9 Composer detected issues in your platform:)

"require": {
    "php": ">=8.1",

}

"config": {
    "platform": {
        "php": "8.1.6"
    },
},

How to solve? Thank in advance.

CodePudding user response:

The messages already contain the answers, the signatures of some methods changed and need to be adjusted in your custom code to be "compatible" with the new symfony version

go to UserRepository.php on line 29

and change the $user parameter from

(UserInterface $user, string $newEncodedPassword)

to

(PasswordAuthenticatedUserInterface $user, string $newHashedPassword)

at the top of the file "use" the interface to not write the full path in method like above:

use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;

The other message just says that your app requires php-version 8.1 minimum but you are running 7.4.30, so you need to upgrade php on the system where you run your app.

  • Related