1.2.1643. 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.1643.1. Connex PHP features¶
1.2.1643.1.1. Suggestions¶
Adopt one of the two syntaxes
1.2.1643.1.2. Specs¶
Short name |
Structures/IsAVersusInstanceof |
Rulesets |
|
Exakat since |
2.6.4 |
PHP Version |
All |
Severity |
|
Time To Fix |
|
Precision |
Very high |
Available in |