1.2.624. Isset() On The Whole Array¶
Isset() works quietly on a whole array. There is no need to test all previous index before testing for the target index.
It also works on chained properties. There is a gain in readability, by avoiding long and hard to read logical expression, and reducing them in one simple isset() call.
There is a gain in performances by using one call to isset(), instead of several. It is a micro-optimization.
<?php
// Straight to the point
if (isset($a[1]['source'])) {
// Do something with $a[1]['source']
}
// Doing too much work
if (isset($a) && isset($a[1]) && isset($a[1]['source'])) {
// Do something with $a[1]['source']
}
// Doing too much work
if (isset($object) && isset($object->p1) && isset($object->p1->property)) {
// Do something with $object->p1->property
}
?>
See also Isset.
1.2.624.1. Connex PHP features¶
1.2.624.1.1. Suggestions¶
Merge all calls in one, and remove all unnecessary calls to isset()
1.2.624.1.2. Specs¶
Short name |
Performances/IssetWholeArray |
Rulesets |
|
Exakat since |
1.5.6 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Instant (5 mins) |
Precision |
High |
Examples |
|
Available in |