<?php
class A {}
class B extends A {}
interface I {}
trait T {}
class C extends B implements I {
use T;
}| Operation | is_a() | is_subclass_of() | instanceof |
|---|---|---|---|
| A of A | ✅ | ❌ | ✅ |
| A of B | ❌ | ❌ | ❌ |
| A of I | ❌ | ❌ | ❌ |
| A of T | ❌ | ❌ | ❌ |
| A of C | ❌ | ❌ | ❌ |
| B of A | ✅ | ✅ | ✅ |
| B of B | ✅ | ❌ | ✅ |
| B of I | ❌ | ❌ | ❌ |
| B of T | ❌ | ❌ | ❌ |
| B of C | ❌ | ❌ | ❌ |
| I of A | ❌ | ❌ | ❌ |
| I of B | ❌ | ❌ | ❌ |
| I of I | ✅ | ❌ | ❌ |
| I of T | ❌ | ❌ | ❌ |
| I of C | ❌ | ❌ | ❌ |
| T of A | ❌ | ❌ | ❌ |
| T of B | ❌ | ❌ | ❌ |
| T of I | ❌ | ❌ | ❌ |
| T of T | ✅ | ❌ | ❌ |
| T of C | ❌ | ❌ | ❌ |
| C of A | ✅ | ✅ | ✅ |
| C of B | ✅ | ✅ | ✅ |
| C of I | ✅ | ✅ | ✅ |
| C of T | ❌ | ❌ | ❌ |
| C of C | ✅ | ❌ | ✅ |
Small change, adding
instanceofto the mixIn case anyone is wondering about the result:
instanceofgives the same results asis_a. It is marginally faster, but it is also more limited in scope (it only accepts an instance as first argument and not a string, and does not accept a variable value as 2nd argument)