Professional Web Applications Themes

isDefined sketchiness - Macromedia ColdFusion

Okay . . . bear with me; I'll try to be brief. Thanks in advance for any replies. My company, after two years of dragging its feet, has upgraded to an MX server and we are in the process of migrating our many sites from one server (CF 5) to the new one. Not suprisingly I suppose, we've hit some bumps. Here's the trouble of the moment. I've been trying to get a handle on it now for a day and a half. One of the application we are moving uses this logic: <cfif IsDefined('URL.iid') AND IsNumeric(URL.iid)>do something <cfelse>do something ...

  1. #1

    Default isDefined sketchiness

    Okay . . . bear with me; I'll try to be brief. Thanks in advance for any
    replies. My company, after two years of dragging its feet, has upgraded to an
    MX server and we are in the process of migrating our many sites from one server
    (CF 5) to the new one. Not suprisingly I suppose, we've hit some bumps.
    Here's the trouble of the moment. I've been trying to get a handle on it now
    for a day and a half. One of the application we are moving uses this logic:
    <cfif IsDefined('URL.iid') AND IsNumeric(URL.iid)>do something <cfelse>do
    something else </cfif> In the course of investigating this I've discovered
    many recommendations against using isDefined to check for a variable value's
    existence and I'll get to that, but bear with me a moment more. Put simply,
    I've been able to determine that if I run the app off a URL like this:
    [url]http://www.myapplication.edu/index.cfm?iid=31[/url] it fails to meet the first
    condition, although you would think it should, since URL.iid isDefined and it's
    value can successfully be converted to a number. But it doesn't. If, on the
    other hand, I create a test directory and include ONLY that piece of logic,
    like this: <cfif IsDefined('URL.iid') AND IsNumeric(URL.iid)>yes <cfelse>no
    </cfif> and feed it the same URL, it does work. Why might this be? I should
    add these two notes to this question. If I check for the existence of
    len('URL.iid') rather than isDefined('URL.iid') it will pass that test and then
    return false when it tried to run the IsNumeric function, because 'Element IID
    in URL is Undefined', to quote the error message. So . . . this leads me to
    believe that in the broader context of the application, Cold Fusion does not
    think that variable's value is defined, whereas stripped down to nothing but
    that code block, it does. Any ideas? Also, I have seen it suggested that
    using StructKeyExists(URL,'iid') sould accomplish the same thing and be more
    reliable . . . however when I do that I get the message, 'You are attempting to
    dereference a scalar variable as if it is a structure with members' and a whole
    different set of problems arises. Can anyone point me it a potentially
    fruitful direction. I have been spinning in one place so long I am starting to
    feel lightheaded. Thanks a lot.

    <cfif IsDefined("URL.iid") AND IsNumeric(URL.iid)>do something
    <cfelse>do something else
    </cfif>

    sofanova Guest

  2. #2

    Default Re: isDefined sketchiness

    Have you tried using a CFPARAM instead of isdefined('') ?
    TurboMini Guest

  3. #3

    Default Re: isDefined sketchiness

    Try CFDUMPing the URL variable. That will tell you if it is defined or not.
    shawnwindler Guest

  4. #4

    Default Re: isDefined sketchiness

    Yes, I have tried CFDUMPing the value, and it is there. Still, isDefined
    returns false. That's the mystery. I've tried a few things using CFPARAM,
    specifically CFPARAMing the URL.iid value to 0 and checking against that, but
    that hasn't worked either . . . is that the course of action you were
    recommending?

    sofanova Guest

  5. #5

    Default Re: isDefined sketchiness

    > len('URL.iid')

    This will always return precisely 7. Because you're asking for the length
    of the string 'URL.iid', not the variable URL.iid.

    My preference - as you suggest - is to use structKeyExists(URL, 'iid').
    Seems to make more sense to me.

    If you're getting the error you cite, it's due to something else in your
    logic being bung, not this bit of code per se.

    I suspect you have something like this, somewhere:

    <cfset url ="a string">

    You can do that in versions previous to CFMX without too many problems (it
    will set variables.url), but it won't work in CFMX, as it assumes you're
    referring to the URL scope.

    --

    Adam
    Adam Cameron Guest

Similar Threads

  1. Isdefined() not working in MX6
    By s6868 in forum Coldfusion - Getting Started
    Replies: 3
    Last Post: September 7th, 08:57 PM
  2. IsDefined In Coldfusion
    By wilsite in forum Coldfusion - Getting Started
    Replies: 4
    Last Post: July 1st, 05:15 AM
  3. Problem with IsDefined()
    By Fizzled in forum Macromedia ColdFusion
    Replies: 2
    Last Post: April 28th, 04:00 PM
  4. <cflock> with isdefined...help.
    By Supra LTD in forum Macromedia ColdFusion
    Replies: 3
    Last Post: March 4th, 07:39 AM
  5. Using IIf() with IsDefined()
    By mate of the state in forum Macromedia ColdFusion
    Replies: 6
    Last Post: March 3rd, 06:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139