← PHP / Laravel · Contents

PHP-020 / Beginner

eval() or dynamic code execution

A03:2021 Injection · CWE-95 Eval Injection

Why is this a problem?

Input strings execute as PHP code.

How to fix it

php
// Process expressions with a dedicated parser and allowlisted operators, without eval.
$allowed = ['+', '-', '*', '/'];  // Calculate directly after token validation

Further reading