1.2.1023. Recalled Condition¶
A recalled condition is a check that is made twice : once in the condition, then again in the body of the structure, to collect the actual value.
Usually, the second call may be skipped by storing the value in a local variable. à
The second call may be necessary when the call is not idempotent.
This is a speed optimisation: when the call is a simple property fetch, or include a local cache, it is a micro-optimisation. Otherwise, it has a good performance potential.
One of the option is to use an iffectation: an affectation in the condition. This serves as cache too. Otherwise, the condition may be calculated and stored before the condition.
<?php
if (get('a')) {
$a = get('a');
echo "Here is a : $a\n";
}
?>
1.2.1023.1. Connex PHP features¶
1.2.1023.1.1. Suggestions¶
Put the result of the call in a variable to cache it.
Use an iffectation in the condition, both store the result and use it in the condition.
1.2.1023.1.2. Specs¶
Short name |
Structures/RecalledCondition |
Rulesets |
|
Exakat since |
2.5.3 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |