user825904 user825904 - 1 year ago 173
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])

Answer Source

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)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download