Solved

Strange CFIF conditional

Posted on 2014-04-10
6
270 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
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.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 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