CF9: What does this appraisal operator evaluate?

I'm stuck and need fresh eyes, please.

I work with someone else's spaghetti code that is no longer around and does not know how much time it is evaluating.

<cfset surveyCount = 0> <cfloop query="surveys"> <cfif evaluate("defaultReport" & ID)> <cfset surveyCount = surveyCount + 1> </cfif> </cfloop> 

In the request dump, I see 9 records that I expect, but because, since the evaluation is not performed, the surveyCount does not increase. I do not see the columns for defaultReport . Over the 15 years of working with CF, I always avoided evaluating (), and now that I need to analyze it, I will completely lose it. Can anyone suggest any recommendations?

Added CFDump image (some column names have been removed for privacy and security): enter image description here

UPDATE I: This file has many cfinclude statements and very little code formatting. As a result, I forgot some cfinclude statements. I found the following. I am still watching, but I want to document this when I rummage.

<cfloop query="surveys"> <cfscript> variables["defaultReport" & ID] = evaluate(thisAssociation & "Price"); </cfscript> </cfloop>

UPDATE II: By resetting the variable scope, I confirmed the variable I'm looking for (finding the query I posted on UPDATE also helped). :)
enter image description here

+5
source share
2 answers

What they wanted to do was increase the surveyCount , but only if this thing: evaluate("defaultReport" & ID) evaluates to true .

From your request dump image, it looks like identifiers are numbers like 144 , 145 , etc.

In this context, you can think of evaluate("defaultReport" & ID) as something like defaultReport144 , defaultReport145 , etc. (these are variables set somewhere in the code).

So the code:

 <cfif evaluate("defaultReport" & ID)> <cfset surveyCount = surveyCount + 1> </cfif> 

becomes (for id 144, first in your request)

 <cfif defaultReport144> <cfset surveyCount = surveyCount + 1> </cfif> 

etc. for other identifiers

So, find your code where the variables are like defaultReport144 , defaultReport145 , etc. set to true or false (0 or 1) .

Sort of:

<cfset defaultReport144 = true />

or maybe they use some expression that evaluates to true or false, for example:

<cfset defaultReport144 = [some expression] />

If you cannot find, perhaps the code has been modified or deleted in the place where these defaultReport... variables were set defaultReport...

ColdFusion evaluate() documentation:
https://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f4e.html

+5
source

You need to look for a variable outside of your query. This variable is named default#ID# . It can be called.

 variables.default#ID# form.default#ID# url.default#ID# request.default#ID# attributes.default#ID# 

and etc.

In principle, ColdFusion will go through all areas until it finds something. (No, this is not a good approach)

If you need to clear this, I would recommend not using such an ambiguous approach. In short, there is no real way to find out what he is evaluating.

+5
source

Source: https://habr.com/ru/post/1275250/


All Articles