CRITICAL
Rule Definition
Optional parameters are an important feature in PHP, but when using them it is always important to have the optional parameter with a given value. This is because the required parameter also needs a value, therefore the optional parameters must always be the first in the list of the parameters. This practice ensures that none of the functions are called without one or more parameters having a value and therefore causing an application crash.
Remediation
Review the source code and try to alter the order of the parameters.
Violation Code Sample
<?php
function foo($param="", $bar){
echo $bar;
}
?>
Fixed Code Sample
<?php
function foo($bar,$param=""){
echo $bar;
}
?>
Related Technologies
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.