CRITICAL
Rule Definition
Source code containing eval-expressions is difficult to test and represents a security risk. The use of eval-expressions should be avoided because it is considered bad practice.
Remediation
Modify the source and consider replacing the eval-expression with regular code.
Violation Code Sample
class CastTest{
public function test($param) {
if ($param === 10) {
eval('$param = 10;');
}
}
}
Fixed Code Sample
<?php
class CastTest {
public function test($param) {
if (90 === $param) {
throw new Exception("Param should not be 90");
}
if (45 === $param) {
throw new Exception("param should not be 45");
}
}
}
try {
$obj = new CastTest();
$obj->test(90);
} catch(Exception $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
Reference
PHPMD - http://phpmd.org/rules/design.html#exitexpression
Related Technologies
Technical Criterion
Programming Practices - Structuredness
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.