user825904 user825904 - 4 months ago 38
PHP Question

How to check if not instance of some class in symfony2

I want to execute some functions if entity is member of few classes but not some.

There is a function called


But is there something like

if ($entity !instanceof [User,Order,Product])


Give them a common interface and then

if (!$entity instanceof ShopEntity)

or stay with

if (!$entity instanceof User && !$entity instanceof Product && !$entity instanceof Order)

I would avoid creating arbitrary functions just to save some characters at a single place. On the other side if you need it "too often", you may have a design flaw? (In the meaning of "too much edge cases" or such)