IF statement takes too long
[...]
Is there a shorter way
Of course.
Just create a function :
function isOfValidClass($obj) { $classNames = array('Class1', 'Class2'); foreach ($classNames as $className) { if (is_a($obj, $className)) { return true; } return false; }
Then you can use this in your code and not worry that your if statement "takes up too much space" (not that you ever thought the problem was, statements should be as they need).
source share