Solved

Strange CFIF conditional

Posted on 2014-04-10
6
269 Views
Last Modified: 2014-04-23
Recently I took over a ColdFusion website for a company that their previous developer had worked on for several years.  He left good documentation but I came across a series of <cfif>  statements on some pages that I can't figure out exactly how they work except for the fact that they are used for debugging and most have <cfdumps> in them.

<cfif 0 or debug>

I've always seen if statements that test a variable against some type of conditional.  This doesn't really seem to do so and im having trouble figuring out how this is working or if im just overlooking something here.

Any suggestions?
Thanks.
0
Comment
Question by:WebStalkers
  • 4
  • 2
6 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 39993081
> I've always seen if statements that test a variable against some type of conditional.

It does, but you can also use shorthand like the code above. CF can implicitly convert numbers like "0" into boolean expressions.  So this:

        <cfif 0>
            ....
        </cfif>

Is just another way of saying:

       <cfif theNumberZero eq true>....</cfif>

That said, the number 0 always equates to false in CF. So that part of the expression will never be true. I'm guessing it is just leftover debugging code.

Anyway, the same shorthand is used for the #debug# variable.  

       <cfif debug>...</cfif>   <=== ie  <cfif debug eq true>

So translated, the whole expression means:

      <cfif theNumberZero eq true OR debug eq true>
      ....
     </cfif>
0
 
LVL 2

Author Comment

by:WebStalkers
ID: 39993117
That makes sense. So with DEBUG in here, would this could be either a variable set on DEBUG in the code or in the url right?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39993150
Yes, that kind of thing is usually set in code or passed via URL.. but since there is no scope, CF is going to walk the chain, looking for a "debug" variable in all of the scopes till it finds one.  Not always a good thing, so when you do find where it's declared, you might want to fix that.

> Local scope
> Arguments
> Thread local (inside threads only)
> Query (not a true scope; variables in query loops)
> Thread
> Variables
.... etc...
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39993152
If you're not sure where it's declared, you could try this undocumented method that dumps most of the standard scopes

http://paulalkema.com/post.cfm/dump-or-list-all-coldfusion-variables-in-all-scopes
0
 
LVL 2

Author Closing Comment

by:WebStalkers
ID: 39995321
Very usefull...I havent seen that.
Thanks again for your help dewd!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40019118
Welcome!

> you could try this undocumented method that dumps most of the standard scopes
Duh! The code is only one line. I should have posted the snippet, in case the link ever breaks. Here it is for the archives:

<cfdump var="#getPageContext().getBuiltInScopes()#"/>
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now