Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Strange CFIF conditional

Posted on 2014-04-10
6
Medium Priority
?
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
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 …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

609 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