Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal offset type in isset or empty in EntityChoiceList.php line 273

Within my Symfony2 project I've attempted to dynamically generate the entities used within my form type, by-passing the use of query builder etc.

To he entity choices property I am supplying an array of entities to be used. On page load everything seems fine and the correct content is displayed. However on form submission I get

Illegal offset type in isset or empty in EntityChoiceList.php line 273

at ErrorHandler ->handle ('2', 'Illegal offset type in isset or empty',
'..../Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php', '273', array('key'     => object(myEntity))) in  ..../Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php at line 273   
            .....
            return isset($entities[$key]) ? $entities[$key] : null; 
            .....

What has me stumped is if I add var_dump(isset($this->entities[$key]));exit; above this line I am returned 'bool(true)' which to me means the key does exist.

As background I have attempted to extend the EntityType, for ease within my project and added:

public function getDefaultOptions(array $options)
{   
    $defaultOptions = array(
        'em'                => null,
        'class'             => 'Acme\TestBundle\Entity\myEntity',
        'property'          => null,
        'query_builder'     => null,
        'choices'           => $this->myEntityArray,
    );

    $options = array_replace($defaultOptions, $options);
    $defaults = parent::getDefaultOptions($options);        
    return $defaults;
}    

Has any one any ideas why I getting this error, or am I going about my issue all wrong anyway, with trying to pass an array of entities to choices?

like image 492
MadManMonty Avatar asked Apr 17 '12 10:04

MadManMonty


1 Answers

If you're getting this while trying to remove an element from an ArrayCollection it's probably because you've typed:

$list->remove($item) instead of $list->removeElement($item)

like image 171
Jonathan Avatar answered Sep 23 '22 01:09

Jonathan