Solved

Strange CFIF conditional

Posted on 2014-04-10
6
272 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Database structure 4 155
CFFILE upload help 98 197
popup load of page and setting up of session 8 50
decryping the string data from visa checkout 5 43
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
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 …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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