在从PHP 5.5升级到PHP 7.0的过程中,Symfony项目遇到了问题。
遵循http://www.doctrine-project.org/2016/06/09/odm-1-1-0-and-1-0-6.html的步骤以确保mongo-ext与学说一起工作。没有发生兼容性升级。
但是会发生以下异常:
PHP Fatal error: Cannot use 'String' as class name as it is reserved in
... vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 26
该问题很可能与composer.json
中的配置问题有关哪个要求阻止编写器更新安装正确的doctrine / mongodb?
PHP Version 7.0.13-0ubuntu0.16.04.1(cli)(NTS)
{
"name": "foo/bar",
"license": "proprietary",
"type": "project",
"autoload": {
"psr-4": {
"": "src/"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"require": {
"php": "^7.0",
"symfony/symfony": "3.2.*",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.3",
"symfony/swiftmailer-bundle": "^2.3",
"symfony/monolog-bundle": "^2.8",
"sensio/distribution-bundle": "^5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "^2.0",
"friendsofsymfony/user-bundle": "~2.0@dev",
"symfony/assetic-bundle": "^2.7",
"liip/imagine-bundle": "^1.4",
"doctrine/mongodb-odm": "^1.1",
"doctrine/mongodb-odm-bundle": "^3.1",
"guzzlehttp/guzzle": "~6.0",
"querypath/QueryPath": ">=3.0.0",
"alcaeus/mongo-php-adapter": "^1.0",
"ext-mongo": "*"
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^2.7"
},
"scripts": {
"post-install-cmd": [
"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-update-cmd": [
"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"
]
},
"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
}
}
}
答案 0 :(得分:3)
结果包中的文档仍然有注释引用。
在代码库中搜索以下任何内容:
\String
\Int
\Bool
\Float
并替换为:
\Field(type="string")
\Field(type="int")
\Field(type="bool")
\Field(type="float")
小心别名
use Doctrine\ODM\MongoDB\Mapping\Annotations AS MongoDB;
在我的代码中,我将搜索前缀为MongoDB,即MongoDB\Int became MongoDB\Field(type="int")