Catchable Fatal Error: Argument 1 passed to ... must be an instance of ..., array given Catchable Fatal Error: Argument 1 passed to ... must be an instance of ..., array given symfony symfony

Catchable Fatal Error: Argument 1 passed to ... must be an instance of ..., array given


Let's take this error apart so you can see how to figure out error messages.

ContextErrorException: Catchable Fatal Error: 

This is the type of the error. You can write an error handler to handle these.

Argument 1 passed to VolleyScout\VolleyScoutBundle\Entity\Users::setPlayer() must be an instance of VolleyScout\VolleyScoutBundle\Entity\Players, 

This means that when Users::setPlayer() is called, you have to call it using a Player object in the argument.

array given, 

This means that instead of a Player object, there was an array in the argument.

called in /Applications/mampstack-5.4.20-0/apache2/htdocs/volleyscout/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 360

This tells you where the problem is: line 360 of PropertyAccessor.php.

and defined in /Applications/mampstack-5.4.20-0/apache2/htdocs/volleyscout/src/VolleyScout/VolleyScoutBundle/Entity/Users.php line 609

This tells you what line of the class Users is involved.

So, all you have to do is change that array on line 360 to a Player object. Then you can move on to the next error.

EDIT:

Because line 360 is being called from somewhere else, you'll have to trace backwards to whatever was calling line 360. In this case, it's this line that's giving you an issue:

$object->$setter($value);

The $value is supposed to be a Player object, not an array. Where is $value coming from?


Had this problem and it drove me nuts.

Once I correctly added this method in the class PlayerType extends Abstract Type:

/*** @param OptionsResolver $resolver*/public function configureOptions(OptionsResolver $resolver){    $resolver->setDefaults(array(        'data_class' => 'AppBundle\Entity\Player'    ));}

It would know that the array should be casted to the right class. And it worked.