I hope the question does not seem strange, but I can clearly explain what I mean. I know that for checks, sometimes you have to be careful about the question of operator precedence or the conditions added in an if.
My question is: Which is the best way to know that an object is not an instance of a class through instanceof
Generally, we use it to find out if it is an instance. So:
if ($object instanceof WallaceMaxters\Timer\Time) {
}
However, what if I want to know that it is not an instance?
I've thought of using it this way:
!$object instanceof Timer
What I want to know is this: When I put !
deny sign in $object
, I run some risk of being wrongly evaluated in my condition; that is, evaluate a boolean instead of an object.
Changing in kids. This ...
$object = new NotTimer;
!$object instanceof Timer
It would be evaluated like this ...
NotTimer(object) instanceof Timer
Or this?
false instanceof Timer
Note
I've seen frameworks that do this:
!($object instanceof Timer)
But is this really necessary, or is there really a possible problem in generating a deny signal condition before instanceof
?