Solved

Strange CFIF conditional

Posted on 2014-04-10
6
268 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

20 Experts available now in Live!

Get 1:1 Help Now