Symfony 3.4.11 doctrine注意:未初始化的字符串偏移量:0

时间:2018-06-11 23:25:31

标签: php symfony console doctrine mapping

我正在使用Symfony,我升级到3.4.11。

但我有一个大问题。当我运行命令时:

php bin/console doctrine:schema:update  --dump-sql

在终端我有下一个错误:

In ClassMetadataInfo.php line 1400:

  Notice: Uninitialized string offset: 0  

真的,我正在搜索并重读文档,但我找不到错误。

非常感谢

更新

$ php bin/console doc:sch:va  -vvv

Mapping
-------


In ClassMetadataInfo.php line 1400:

  [Symfony\Component\Debug\Exception\ContextErrorException]  
  Notice: Uninitialized string offset: 0                     


Exception trace:
 Doctrine\ORM\Mapping\ClassMetadataInfo->_validateAndCompleteFieldMapping() at /home/devel/tests4/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:2355

 Doctrine\ORM\Mapping\ClassMetadataInfo->mapField() at /home/devel/tests4/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php:333

 Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass() at /home/devel/tests4/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:102

 Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass() at /home/devel/tests4/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:151

 Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at /home/devel/tests4/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:333

 Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /home/devel/tests4/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78

 Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() at /home/devel/tests4/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:217

 Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /home/devel/tests4/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:115

 Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() at /home/devel/tests4/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/SchemaValidator.php:68

 Doctrine\ORM\Tools\SchemaValidator->validateMapping() at /home/devel/tests4/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php:69

 Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand->execute() at /home/devel/tests4/vendor/doctrine/doctrine-bundle/Command/Proxy/ValidateSchemaCommand.php:34

 Doctrine\Bundle\DoctrineBundle\Command\Proxy\ValidateSchemaCommand->execute() at /home/devel/tests4/vendor/symfony/console/Command/Command.php:251

 Symfony\Component\Console\Command\Command->run() at /home/devel/tests4/vendor/symfony/console/Application.php:964

 Symfony\Component\Console\Application->doRunCommand() at /home/devel/tests4/vendor/symfony/framework-bundle/Console/Application.php:86

 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /home/devel/tests4/vendor/symfony/console/Application.php:248

 Symfony\Component\Console\Application->doRun() at /home/devel/tests4/vendor/symfony/framework-bundle/Console/Application.php:74

 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/devel/tests4/vendor/symfony/console/Application.php:148

 Symfony\Component\Console\Application->run() at /home/devel/tests4/bin/console:39

4 个答案:

答案 0 :(得分:2)

感谢大家帮助我。

我修复了错误,并在此处找到了正确的答案:https://plus.google.com/+KamilZabdyr/posts/fb5xYGyyyY8

这里快速修复了ORM非常常见的错误:

PHP注意:未初始化的字符串偏移量:0?/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

通常会抛出它,因为ORM列名称标记为空。因此,请检查所有模型文件中的任何空名称。 E.g:

@ORM \ Column(name =“”,type =“string”,length = 12)

答案 1 :(得分:0)

这是我遇到类似问题的第一个Google广告:

bin/console doctrine:migrations:diff

In MySqlSchemaManager.php line 243:

  Notice: Uninitialized string offset: 0  

当我检查其他机器上的代码时,它可以工作,但是这台特定的机器出现了上述故障。 我的问题是与MariaDB的交互。 当我从以下位置升级时:

mysql --version
mysql  Ver 15.1 Distrib 10.1.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

收件人:

mysql --version
mysql  Ver 15.1 Distrib 10.3.11-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

问题消失了。

升级到10.1.38-MariaDB没有帮助。

答案 2 :(得分:0)

我还通过Symfony控制台体验了“未初始化的字符串偏移量:0”的理论。

In MySqlSchemaManager.php line 223:
    Notice: Uninitialized string offset: 0  

在我的情况下,这是教义配置和(本地)服务器版本之间的MariaDB版本不匹配。我看到@SamuelÅslund的更新MariaDB的建议,发现它有点多余,但这确实使我朝数据库版本问题的方向发展。

doctrine.yaml 中(Symfony 4 +)

 doctrine:
    dbal:
        server_version: 'mariadb-10.1.36'

通过symfony-console安装后,已预先配置:

 doctrine:
    dbal:
        server_version: 'mariadb-10.3.11'

答案 3 :(得分:0)

为了记录,我在用大张旗鼓的文档生成文档时遇到了同样的问题,它在entity中的setter函数的注释中:

    /**
     * @param Survey[]|[] $surveys
     */
    public function setSurvey(array $surveys = [])
    {
        $this->surveys = $surveys;
    }

错误的时间

    /**
     * @param Survey[] $surveys
     */
    public function setSurvey(array $surveys)
    {
        $this->surveys = $surveys;
    }

是正确的。

将潜在的空数组作为参数的注释会导致错误(我认为这也是一种不好的做法,setter函数不能没有参数!)。