I am aware that instanceof is an operator and that is_a is a method.
Is the method slower in performance? What would you prefer to use?
Here are performance results obtained from here:
instanceof
is faster.
Functions
function method_1($a = null) {
return is_object($a) && is_a($a, 'Example');
}
function method_2($a = null) {
return is_a((object) $a, 'Example');
}
function method_3($a = null) {
return $a instanceof 'Example';
}
Times (run 5000 times each)
0.00573397 // method_1(5)
0.01437402 // method_2(5)
0.00376201 // method_3(5)