I have two classes, A and B. B extends class A.
If I execute instance of A on an instance of B, it returns TRUE.
How can this be avoided?
This is how instanceof works, and correctly so: if B inherits from A, it is also of type A.
However, you can check the precise class by using get_class() instead:
if (get_class($b_instance) == 'A') {
// Not true
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With