jeudi 27 juillet 2017

PHP how to check if array is a collection of specific object

In my class I have a method which expects as array, and this array should be used differently depending on the collection type. The array items should be objects, and I need to know which class instance these objects are.

For example: in the array($obj1, $obj2), I need to check the instance of these objects, which class they were created from.

I know I could iterate the array and check instanceof of each item... but is there any better way to do so?




Aucun commentaire:

Enregistrer un commentaire