Is type checking considered bad practice even if you are checking against an interface? I understand that you should always program to an interface and not an implementation – is this what it means?
For example, in PHP, is the following OK?
if($class instanceof AnInterface) { // Do some code }
Or is there a better way of altering the behaviour of code based on a class type?
Edit: Just to be clear I am talking about checking whether a class implements an interface not just that it is an instance of a certain class.
As long as you follow the LSP, I don’t see a problem. Your code must work with any implementation of the interface. It’s not a problem that certain implementations cause you to follow different code paths, as long as you can correctly work with any implementation of the interface.
If your code doesn’t work with all implementations of the interface, then you shouldn’t use the interface in the first place.