Doctrine ODM - PHP7 - 不能使用 Int/String 作为 Class 名称
Doctrine ODM - PHP7 - Can not use Int/String as Class Name
在从 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 版本 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"
}
}
}
原来捆绑包中的文档仍然有注释引用。
在代码库中搜索以下任一内容:
\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")
在从 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 版本 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"
}
}
}
原来捆绑包中的文档仍然有注释引用。
在代码库中搜索以下任一内容:
\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")