Vendor updates broke FOS User Bundle with “Call to a member function has() on a non-object”

拜拜、爱过 提交于 2019-12-29 08:48:07

问题


I updated my vendors for a Symfony 2.8 project and suddenly the login page isn't loading – instead I get this:

Error: Call to a member function has() on a non-object in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php at line 184

"name": "hazardlog",
"license": "proprietary",
"type": "project",
"autoload": {
    "psr-4": {
        "": "src/"
    },
    "classmap": [
        "app/AppKernel.php",
        "app/AppCache.php"
    ]
},
"repositories": [
    {
        "type": "package",
        "package": {
            "name": "jquery/jquery",
            "version": "1.11.1",
            "dist": {
                "url": "https://code.jquery.com/jquery-1.11.1.js",
                "type": "file"
            }
        }
    }
],
"require": {
    "php": ">=5.3.9",
    "symfony/symfony": "2.8.*",
    "doctrine/orm": "^2.4.8",
    "doctrine/doctrine-bundle": "~1.4",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~5.0",
    "sensio/framework-extra-bundle": "^3.0.2",
    "incenteev/composer-parameter-handler": "~2.0",
    "braincrafted/bootstrap-bundle": "~2.0",
    "twbs/bootstrap": "3.0.*",
    "jquery/jquery":  "1.11.*",
    "hwi/oauth-bundle": "^0.5.0",
    "friendsofsymfony/user-bundle": "~2.0@dev",
    "stephanecollot/datetimepicker-bundle": "dev-master"
},
"require-dev": {
    "sensio/generator-bundle": "~3.0",
    "symfony/phpunit-bridge": "~2.7"
},
"scripts": {
    "symfony-scripts": [
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
    ],
    "post-install-cmd": [
        "@symfony-scripts"
    ],
    "post-update-cmd": [
        "@symfony-scripts"
    ]
},
"config": {
    "bin-dir": "bin"
},
"extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "symfony-assets-install": "relative",
    "incenteev-parameters": {
        "file": "app/config/parameters.yml"
    }
}

回答1:


I have seen this sort of question several times but I could not find one with an accepted answer and explanation. So here goes.

The basic problem lies with:

"friendsofsymfony/user-bundle": "~2.0@dev",

Back when Symfony 2.8/3.0 was first released, the stable 1.x version of FOSUserBundle no longer worked. The 2.x version has been in development for years with no actual road map in sight for when it would be stabilized. So the development branch was hacked up to get it working. And folks had no choice but to use it which of course is dangerous because you never know when a development change might in fact break your code.

Time went by and eventually a stable 2.x version of the FOSUserBundle was released. However, quite a few developers never got around to updating their dependencies and continued to use the master branch.

Fast forward to the present. The release of Symfony 4 has now triggered a fair amount of development in the master branch. Development which is introducing breaking changes to existing 2.8 (and probably 3.0) code.

The bottom line is to use a stable branch with:

"friendsofsymfony/user-bundle": "~2.0",

followed by a composer update.




回答2:


its strange but today i make a composer update - with the right configutaiton in composer.json

"friendsofsymfony/user-bundle": "~2.0",

But the same error one month ago occur:

Error: Call to a member function has() on null in in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php at line 184




回答3:


For those using Symfony 3.2, it looks like version "~2.1" throws same error along with the OP's version "~2.0@dev".

This worked:

"friendsofsymfony/user-bundle": "2.0"

Keeping it at 2.0 did the trick for me.




回答4:


I have kinda the same issue but I do not have the @dev (and never had)

Stack trace is a bit different :

in vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php at line 234



回答5:


had a problem like this here but solved,i just did the opposite of this. i had:

"friendsofsymfony/user-bundle": "^2.1",

in my composer.json file which give me a Call to a member function has() on null error to solve this i Actually add "@dev it became:

"friendsofsymfony/user-bundle": "^2.1@dev",

then updated my composer with :

composer update



来源:https://stackoverflow.com/questions/48153155/vendor-updates-broke-fos-user-bundle-with-call-to-a-member-function-has-on-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!