Evaluate() function in coldfusion is not working

122 Views Asked by At

I am getting error when using evaluate() in coldfusion 2021. Please see the screenshotenter image description here

Can I know what's the reason behind it or is there any solution to solve this? In my project I have used this function in many place. Please help me on this.

1

There are 1 best solutions below

0
Adam Cameron On

That's trycf.com, right? They've disabled evaluate. The message even says this.

On a well-locked-down server, things like evaluate are often disabled as they are a penetration vector unless handled properly.

As trycf.com is - by design - for running any arbitrary CFML, the server needs to be well locked down. And it is.

However I doubt your concern is really about trycf.com. I presume it's for some other server you use? It'll be for the same reason: security.

There's almost never a reason to use evaluate, and using it is considered poor practice in a lot of circles. Given you can't use it in your case, I'd refactor the code to not need it.


In your specific example (also please in future don't post pictures of code and/or error messages: post the text!) you don't need evaluate. You just need this:

prevYear = year(now()) - 1

evaluate is for evaluating one or more strings that contain code expressions. It's absolutely pointless here. One should always have read the docs for any programming construct one is using. Especially if one is having problems with it.