How to check if not instance of some class in symfony2

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)


PHP manual says: http://php.net/manual/en/language.operators.type.php

!($a instanceof stdClass)

This is just a logical and "grammatically" correct written syntax.

!$class instanceof someClass

The suggested syntax above, though, is tricky because we are not specifying which exactly is the scope of the negation: the variable itself or the whole construct of $class instanceof someclass. We will only have to rely on the operator precendence here [Edited, thanks to @Kolyunya].