Thought I'd throw in my 2c worth, seeing it was brought up at CFUG last night... have strung together a couple of custom tags that could achieve this for you.

I've used cf_strict and cf_declare as the tagnames, but call them what you like, and don't forget they can be thrown into a tag library and used with cfimport under mx.


Have a play with this - just cut along the dotted lines ;o)

-=-=-=- Source of test.cfm -=-=-=-
<CF_STRICT>
        <CF_DECLARE colour1="red">
        <CF_DECLARE colour2="green">
        <CF_DECLARE colour3="pink">
        <CF_DECLARE colour4="">
        <CFSET colour3 = colour3 & colour2>
        <CFSET color4 = colour1 & colour2>
</CF_STRICT>
<CFDUMP var="#variables#">
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

-=-=-=- Source of strict.cfm -=-=-=-
<CFSWITCH expression="#thistag.executionmode#">
        <CFCASE value="start">
                <CFSET request.declared_vars = "">
        </CFCASE>
        <CFCASE value="end">
                <CFLOOP collection="#caller.variables#" item="thisvar">
                        <CFIF not ListFindNoCase(request.declared_vars,variables.thisvar)>
                                 <CFOUTPUT>Not found:#thisvar#<br></CFOUTPUT>
                        </CFIF>
                </CFLOOP>
        </CFCASE>
</CFSWITCH>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

-=-=-=- Source of declare.cfm -=-=-=-
<CFLOOP collection="#attributes#" ITEM="thisvar">
        <CFSET caller.variables[#thisvar#] = attributes[#thisvar#]>
        <CFSET request.declared_vars = listappend(request.declared_vars,thisvar)>
</CFLOOP>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Note a few points:
- This works on the variables scope only, but could easily be adapted to other scopes.
- You can use <CF_DECLARE myvariable> syntax, but it sets the value to "true"
- I've only done a simple cfoutput at the end tag as a warning, but you could replace this with a _javascript_ popup, a CFLOG entry, and/or insert code to disable the behaviour completely in a production environment (bugs? what bugs?).

Food for thought....


Vaughan.



"Warren" <[EMAIL PROTECTED]>

02/04/2003 10:02 AM

Please respond to
"CFAussie Mailing List" <[EMAIL PROTECTED]>

To
"CFAussie Mailing List" <[EMAIL PROTECTED]>
cc
Subject
[cfaussie] OT: Force variables to be declared





is there a CF version of "option explicit" (ASP) to force variables to be
declared to cut down on typo's

1)<cfset rowColour = "">
2)...
3)...
4)<cfif theCount mod 2 eq 0>
5)  <cfset rowColour = colourA>
6)<cfelse>
7)  <cfset rowColor = colourB>
8)</cfif>

look at line 7. I've accidentally declared a new variable!

any way around this?



****************************************************************************
If this communication is not intended for you and you are not an authorised
recipient of this email you are prohibited by law from dealing with or
relying on the email or any file attachments. This prohibition includes
reading, printing, copying, re-transmitting, disseminating, storing or in
any other way dealing or acting in reliance on the information. If you
have received this email in error, we request you contact ABN AMRO Morgans
Limited immediately by returning the email to [EMAIL PROTECTED]
and destroy the original. We will refund any reasonable costs associated
with notifying ABN AMRO Morgans. This email is confidential and may contain
privileged client information. ABN AMRO Morgans has taken reasonable steps
to ensure the accuracy and integrity of all its communications, including
electronic communications, but accepts no liability for materials
transmitted. Materials may also be transmitted without the knowledge of ABN
AMRO Morgans. ABN AMRO Morgans Limited its directors and employees do not
accept liability for the results of any actions taken or not on the basis
of the information in this report. ABN AMRO Morgans Limited and its
associates hold or may hold securities in the companies/trusts mentioned
herein. Any recommendation is made on the basis of our research of the
investment and may not suit the specific requirements of clients.
Assessments of suitability to an individual's portfolio can only be made
after an examination of the particular client's investments, financial
circumstances and requirements.
****************************************************************************
--- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] MX Downunder AsiaPac DevCon - http://mxdu.com/

Reply via email to