WDPEjoe wrote:and it turns out it's tedious to add the CLASS constant to every definition & call.
Only if you've already written them all.
Also, the argument generally doesn't even make sense in the context of the function being called.
So would NogDog's.
you can't rely on the input being valid
Then in that case, to start with, you can pass the object itself to the function, have all "valid" classes implement a particular interface, and have a type hint on the function declaration to limit the argument to objects that implement that interface. Then if necessary you can use instanceof to look at the object in more specificity.
An object of an invalid class could still create a bogus object of a "valid" class and pass that to fction, of course, but then again it could also create a bogus object of a valid class and have it call fction(). And if there are enough controls surrounding the creation of objects of valid classes to prevent that, then there is enough in place for fction() to check the object it's being passed for validity without simply relying on whether it's of the right class or not.
NogDog's code has the advantage that there is more information available. For classes and objects more information still is accessible through reflection.
Depends entirely on what "fction()" is supposed to do, of course.