/e (Eval (deprecated))
What is /e (Eval (deprecated))?
/e (Eval (deprecated)): A historical PHP modifier that evaluated the replacement string as PHP code inside preg_replace(). The e modifier once made PHP's preg_replace() run the replacement as PHP code. It was deprecated in PHP 5.5 and removed in PHP 7.0, because it was a common source of remote code execution bugs. The danger was simple. If any part of the matched text came from a user, an attacker could craft input that ended up being executed on your server.
Frequently asked questions about /e (Eval (deprecated))
What should you keep in mind with /e (Eval (deprecated))?
If you find /e in old code, replace it with preg_replace_callback(). You pass a function that receives the match and returns the replacement, so the result is computed in normal PHP code and user input is only ever treated as data. Legacy code that still uses /e will not run on any supported PHP version, so finding it usually means the project needs a broader upgrade. That is worth knowing before you estimate the work.
At a glance
| Category | Regex flags |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |