Coldfusion's Evaluate()

Today I was going through an application turned over by a contractor and I began noticing that evaluate() was used frequently through out the code.

I thought by now we’d all know that using Coldfusion’s evaluate() function should be avoided. Evaluate() is a performance hit and is an indication of sloppy code. It may be possible that there are situations where it is unavoidable, but in my experience if you are considering to use evaluate() to solve a problem its a red flag that there is a better solution if you just think a little longer.

Structures

evaluate() example:


     

With Structures it is easy to avoid using evaluate() as you can dynamically create the struct key such as:


     

Queries

evaluate() example:



     

Queries are not much different than structures. The trick is that you’ll need to explicitly define the current row. This is something that is normally implicit.



     

Function Calls



Dynamically declaring function calls is a neat trick. The example code is a very (very) basic generic getter function, perhaps utilized within onMissingMethod(). Given any string it will try to call a getter function for that property. There is no other syntax to create this call. But using evaluate() should be a red flag. When you get into a situation such as this you should really ask yourself why you are organizing your code this way.

Perhaps you could forgo building a named function for each property and restructure your generic getter function to work like this:



or possibly even simpler as:



You should definitely be asking yourself why you would call a generic getter function if you built named getter functions. (Maybe you’ve made the methods private?) This is a simple example, but either way evaluate() is most often a sign of a larger coding problem.

php5apache2_2.dll missing from PHP 5.3 zip

Today I did a reinstall of Apache and PHP. I used the latest versions of both Apache and PHP.

I downloaded the VC6 5.3 zip file but came to a problem when trying to install PHP as there was no php5apache2_2.dll file included in the zip download. I had downloaded the non-thread-safe version of PHP5.3. Apache2.2 only works with the thread-safe version, but the PHP downloads page does not make this clear. The PHP download page says:

Which version do I choose?
If you are using PHP with Apache 1  or Apache2 from apache.org
you need to use the VC6 versions of PHP

So for anyone else having this problem, use the thread-safe version!

(and skip the installer: its useless)