In my symfony project I have an array $productContainer with some values like (php dump):
array:2 [▼
0 => "value1"
1 => "value2"
]
I pass this array in the Product entity by findBy method in my controller like this:
$products = $this->getDoctrine()->getRepository('MyBundle:Product')
->findByValue($productContainer);
The results between the findBy method and the array values match very well.
But when I check if the array is an instance of my class Product like this:
dump($products instanceof Product);
die;
it retuns me : false
I understand that $products is an array and not an object, but how can I declare my array $products as an instanceof Product entity ?
Edit
In order to be more precise, I need to declare or check if my values of array $products are instanceof Product because in the same controller, I have to pass array $products in a queryBuilder for another entity like this:
$entity = $this->getDoctrine()->getRepository('MyBundle:Entity')
->getEntityWithProducts($slug, $products);
I recover the array $products by a $_POST method (Request $request)
Its a controller method that I retun into JsonResponse, that why I proceed in that way.
Productentity! It is because he usesfindBymethod - it never returns one object, it returns either array of objects (even if there is only one) or null. He need either to check each array member forinstanceofor don't need to check any of them.Productentity. :)