First of all, thank you for read my first stackoverflow question!!!
I have the code below:
eval('return ('.$statement.');')
I'm creating a template engine for study purposes, so, i need that code for some conditional actions on my views.
The objective of this code is execute a statement and return the logical result.
Suppose $statement = '1 == 1';
this return true,
but, if i put $statement = 'cookie()->has('name');'
this gives the following error:
Parse error: syntax error, unexpected '&' in /var/www/html/exemplo.com/core/Instead/src/TemplateEngines/TemplateEngine.php(96) : eval()'d code on line 1
Note that the cookie function already exists and is accessible globally, and return 1, only 1.
Any idea?? Solutions? Thanks Again.
It's strange, but for some reason, $statement = filter_var($statement, FILTER_SANITIZE_STRING)
is causing the error; after replace this function to strip_tags
the error is gone.