【发布时间】:2015-06-23 20:02:07
【问题描述】:
Symfony 在我的管理后端的 CRUD 页面上给我一个错误:
Symfony 2.6 exception: Expected argument of type "object or array", "NULL" given
完整的堆栈跟踪如下,
相关源文件的第 132 行在这里:
https://github.com/symfony/PropertyAccess/blob/master/PropertyAccessor.php
以前有没有人遇到过这种类型的异常?我到底应该在哪里寻找不存在的树枝价值?在 FormType 对象中?实体?配置 .yml 设置?
我尝试 git bisecting 来查找错误,我尝试回滚 git 中的代码,但我就是不知道如何调试它,它太抽象了。
全栈跟踪:
[1] Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException: Expected argument of type "object or array", "NULL" given
at n/a
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php line 232
at Symfony\Component\PropertyAccess\PropertyAccessor->readPropertiesUntil(object(User), object(PropertyPath), '2', true)
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php line 58
at Symfony\Component\PropertyAccess\PropertyAccessor->getValue(object(User), object(PropertyPath))
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php line 252
at Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList->extractLabels(array(object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User)), array('test test', 'test test', 'test test', 'Coughlin Tom', 'test test', 'Smith John', 'Eric Spoelstra', 'James LeBron', 'Chris Bosh', 'Roy Ronalds', 'Development Preview', 'Roy Testing', 'Tester TesterLast'))
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php line 146
at Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList->initialize(array(object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User), object(User)), array(), array())
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php line 437
at Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList->load()
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php line 174
at Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList->getPreferredViews()
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php line 101
at Symfony\Component\Form\Extension\Core\Type\ChoiceType->buildView(object(FormView), object(Form), array('block_name' => null, 'disabled' => false, 'label' => null, 'label_format' => null, 'translation_domain' => null, 'auto_initialize' => true, 'trim' => true, 'read_only' => false, 'max_length' => null, 'pattern' => null, 'property_path' => null, 'mapped' => true, 'by_reference' => true, 'virtual' => null, 'method' => 'POST', 'action' => '', 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.', 'error_mapping' => array(), 'cascade_validation' => false, 'invalid_message' => 'This value is not valid.', 'invalid_message_parameters' => array(), 'allow_extra_fields' => false, 'extra_fields_message' => 'This form should not contain extra fields.', 'csrf_protection' => true, 'csrf_field_name' => '_token', 'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.', 'csrf_provider' => object(CsrfProviderAdapter), 'intention' => null, 'multiple' => false, 'expanded' => false, 'choices' => null, 'preferred_choices' => array(), 'query_builder' => null, 'group_by' => null, 'attr' => array(), 'data_class' => null, 'empty_data' => '', 'required' => false, 'error_bubbling' => false, 'label_attr' => array(), 'inherit_data' => false, 'compound' => false, 'validation_groups' => null, 'constraints' => array(), 'csrf_token_manager' => object(CsrfProviderAdapter), 'csrf_token_id' => null, 'property' => 'profile.fullname', 'class' => 'SYUsersBundle:User', 'em' => object(EntityManager), 'loader' => object(ORMQueryBuilderLoader), 'choice_list' => object(EntityChoiceList), 'empty_value' => '', 'placeholder' => ''))
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Component/Form/ResolvedFormType.php line 162
at Symfony\Component\Form\ResolvedFormType->buildView(object(FormView), object(Form), array('block_name' => null, 'disabled' => false, 'label' => null, 'label_format' => null, 'translation_domain' => null, 'auto_initialize' => true, 'trim' => true, 'read_only' => false, 'max_length' => null, 'pattern' => null, 'property_path' => null, 'mapped' => true, 'by_reference' => true, 'virtual' => null, 'method' => 'POST', 'action' => '', 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.', 'error_mapping' => array(), 'cascade_validation' => false, 'invalid_message' => 'This value is not valid.', 'invalid_message_parameters' => array(), 'allow_extra_fields' => false, 'extra_fields_message' => 'This form should not contain extra fields.', 'csrf_protection' => true, 'csrf_field_name' => '_token', 'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.', 'csrf_provider' => object(CsrfProviderAdapter), 'intention' => null, 'multiple' => false, 'expanded' => false, 'choices' => null, 'preferred_choices' => array(), 'query_builder' => null, 'group_by' => null, 'attr' => array(), 'data_class' => null, 'empty_data' => '', 'required' => false, 'error_bubbling' => false, 'label_attr' => array(), 'inherit_data' => false, 'compound' => false, 'validation_groups' => null, 'constraints' => array(), 'csrf_token_manager' => object(CsrfProviderAdapter), 'csrf_token_id' => null, 'property' => 'profile.fullname', 'class' => 'SYUsersBundle:User', 'em' => object(EntityManager), 'loader' => object(ORMQueryBuilderLoader), 'choice_list' => object(EntityChoiceList), 'empty_value' => '', 'placeholder' => ''))
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/DataCollector/Proxy/ResolvedTypeDataCollectorProxy.php line 111
at Symfony\Component\Form\Extension\DataCollector\Proxy\ResolvedTypeDataCollectorProxy->buildView(object(FormView), object(Form), array('block_name' => null, 'disabled' => false, 'label' => null, 'label_format' => null, 'translation_domain' => null, 'auto_initialize' => true, 'trim' => true, 'read_only' => false, 'max_length' => null, 'pattern' => null, 'property_path' => null, 'mapped' => true, 'by_reference' => true, 'virtual' => null, 'method' => 'POST', 'action' => '', 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.', 'error_mapping' => array(), 'cascade_validation' => false, 'invalid_message' => 'This value is not valid.', 'invalid_message_parameters' => array(), 'allow_extra_fields' => false, 'extra_fields_message' => 'This form should not contain extra fields.', 'csrf_protection' => true, 'csrf_field_name' => '_token', 'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.', 'csrf_provider' => object(CsrfProviderAdapter), 'intention' => null, 'multiple' => false, 'expanded' => false, 'choices' => null, 'preferred_choices' => array(), 'query_builder' => null, 'group_by' => null, 'attr' => array(), 'data_class' => null, 'empty_data' => '', 'required' => false, 'error_bubbling' => false, 'label_attr' => array(), 'inherit_data' => false, 'compound' => false, 'validation_groups' => null, 'constraints' => array(), 'csrf_token_manager' => object(CsrfProviderAdapter), 'csrf_token_id' => null, 'property' => 'profile.fullname', 'class' => 'SYUsersBundle:User', 'em' => object(EntityManager), 'loader' => object(ORMQueryBuilderLoader), 'choice_list' => object(EntityChoiceList), 'empty_value' => '', 'placeholder' => ''))
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Component/Form/ResolvedFormType.php line 159
at Symfony\Component\Form\ResolvedFormType->buildView(object(FormView), object(Form), array('block_name' => null, 'disabled' => false, 'label' => null, 'label_format' => null, 'translation_domain' => null, 'auto_initialize' => true, 'trim' => true, 'read_only' => false, 'max_length' => null, 'pattern' => null, 'property_path' => null, 'mapped' => true, 'by_reference' => true, 'virtual' => null, 'method' => 'POST', 'action' => '', 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.', 'error_mapping' => array(), 'cascade_validation' => false, 'invalid_message' => 'This value is not valid.', 'invalid_message_parameters' => array(), 'allow_extra_fields' => false, 'extra_fields_message' => 'This form should not contain extra fields.', 'csrf_protection' => true, 'csrf_field_name' => '_token', 'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.', 'csrf_provider' => object(CsrfProviderAdapter), 'intention' => null, 'multiple' => false, 'expanded' => false, 'choices' => null, 'preferred_choices' => array(), 'query_builder' => null, 'group_by' => null, 'attr' => array(), 'data_class' => null, 'empty_data' => '', 'required' => false, 'error_bubbling' => false, 'label_attr' => array(), 'inherit_data' => false, 'compound' => false, 'validation_groups' => null, 'constraints' => array(), 'csrf_token_manager' => object(CsrfProviderAdapter), 'csrf_token_id' => null, 'property' => 'profile.fullname', 'class' => 'SYUsersBundle:User', 'em' => object(EntityManager), 'loader' => object(ORMQueryBuilderLoader), 'choice_list' => object(EntityChoiceList), 'empty_value' => '', 'placeholder' => ''))
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/DataCollector/Proxy/ResolvedTypeDataCollectorProxy.php line 111
at Symfony\Component\Form\Extension\DataCollector\Proxy\ResolvedTypeDataCollectorProxy->buildView(object(FormView), object(Form), array('block_name' => null, 'disabled' => false, 'label' => null, 'label_format' => null, 'translation_domain' => null, 'auto_initialize' => true, 'trim' => true, 'read_only' => false, 'max_length' => null, 'pattern' => null, 'property_path' => null, 'mapped' => true, 'by_reference' => true, 'virtual' => null, 'method' => 'POST', 'action' => '', 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.', 'error_mapping' => array(), 'cascade_validation' => false, 'invalid_message' => 'This value is not valid.', 'invalid_message_parameters' => array(), 'allow_extra_fields' => false, 'extra_fields_message' => 'This form should not contain extra fields.', 'csrf_protection' => true, 'csrf_field_name' => '_token', 'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.', 'csrf_provider' => object(CsrfProviderAdapter), 'intention' => null, 'multiple' => false, 'expanded' => false, 'choices' => null, 'preferred_choices' => array(), 'query_builder' => null, 'group_by' => null, 'attr' => array(), 'data_class' => null, 'empty_data' => '', 'required' => false, 'error_bubbling' => false, 'label_attr' => array(), 'inherit_data' => false, 'compound' => false, 'validation_groups' => null, 'constraints' => array(), 'csrf_token_manager' => object(CsrfProviderAdapter), 'csrf_token_id' => null, 'property' => 'profile.fullname', 'class' => 'SYUsersBundle:User', 'em' => object(EntityManager), 'loader' => object(ORMQueryBuilderLoader), 'choice_list' => object(EntityChoiceList), 'empty_value' => '', 'placeholder' => ''))
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 1058
at Symfony\Component\Form\Form->createView(object(FormView))
in /srv/sy4/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 1061
at Symfony\Component\Form\Form->createView()
in /srv/sy4/src/SK/AdminBundle/Controller/CrudController.php line 100
at SK\AdminBundle\Controller\CrudController->doIndex()
in /srv/sy4/src/SK/AdminBundle/Controller/CrudController.php line 30
at SK\AdminBundle\Controller\CrudController->indexAction()
in line
at call_user_func_array(array(object(TeamsController), 'indexAction'), array())
in /srv/sy4/app/bootstrap.php.cache line 3039
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in /srv/sy4/app/bootstrap.php.cache line 3001
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in /srv/sy4/app/bootstrap.php.cache line 3150
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in /srv/sy4/app/bootstrap.php.cache line 2391
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /srv/sy4/web/app_dev.php line 28
【问题讨论】:
-
似乎它正在尝试使用选择字段(对于用户对象)呈现表单类型,但选择为空(null)。您可以发布表单类型的配置,特别是带有用户选择字段的部分...
-
@DonaldP 您先生,是个巫师。这正是问题所在,(我试图过滤用户个人资料上的视图列表,下拉选项是用户个人资料的全名。一旦我停止询问属性“profile.fullname”(只有一个方法)并且刚刚使用了“配置文件”,它开始正确地使用 __toString 来生成用户选择名称。如果你把它作为答案,我肯定会接受。
-
感谢您解决了问题
标签: php symfony debugging symfony-2.6