1.2.1632. is_a() Versus instanceof¶
is_a() and instanceof have the same functional use: checking if an object is of a specific class.
The analyzed code has less than 10% of one of them: either is_a() or instanceof. For consistency reasons, it is recommended to make them all the same.
It happens that is_a() or instance are used depending on coding style and files. One file may be consistently using is_a(), while the others are all using instanceof.
<?php
if (is_a($object, $class)) { /**/ }
if ($object instanceof $class) { /**/ }
// Note : code is not representative of actual code.
?>
1.2.1632.1. Suggestions¶
Adopt one of the two syntaxes
1.2.1632.2. Specs¶
Short name |
Structures/IsAVersusInstanceof |
Rulesets |
|
Exakat since |
2.6.4 |
Severity |
|
Time To Fix |
|
Precision |
Very high |
Features |
instanceof |
Available in |