Rule Definition
In PHP the assignment of a function that has no return will always result in the value 'null'. This means that this statement has no effect. If the value returned by the function is re-used in the source code, this could produce a crash of part of the application or even the entire application.
Remediation
Modify the source code and always check the returned value of a function before assigning it. Check that there is always an implementation for a return statement in the function.
Violation Code Sample
<?php
function foo($param1, $param2){
$param1 + $param2;
}
$result = foo(1,2);
//further processing
?>
Fixed Code Sample
<?php
function foo($param1, $param2){ $ result=
$param1 + $param2; return $result;
}
$result = foo(1,2);
//further processing
?>
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.