What are some potential pitfalls of using the eval function in PHP to calculate mathematical expressions?

Using the eval function in PHP to calculate mathematical expressions can be risky as it allows for the execution of arbitrary code, which can lead to security vulnerabilities if user input is not properly sanitized. To avoid this issue, it is recommended to use alternative methods such as the built-in mathematical functions or libraries specifically designed for mathematical computations.

// Using built-in mathematical functions to calculate expressions
$expression = "2 + 3 * 4";
$result = eval("return $expression;"); // Avoid using eval for mathematical calculations
echo $result;