Skip to main content
September 3, 2009
Question

StructDelete or StructIsEmpty broken in CF8?

  • September 3, 2009
  • 5 replies
  • 3117 views

I have found what appears to be a CF8 bug?

My code:

<cfdump var="#URL#">
<cfset rc = StructDelete(URL, "SN", "true")>
<cfdump var="RC: #rc#"><br />
<cfdump var="StructIsEmpty: #StructIsEmpty(URL)#">
<cfdump var="#URL#">
<cfabort>

In my case the URL has one key called "SN".  I delete it using StructDelete function.

I then immediately test it for emptiness...using StructIsEmpty, but it displays No. Yet, a dump of the URL struct shows it is.

What gives?????

Here's the output I get:

struct
SN/products/fpga/ecp/index.cfm

RC: YES
StructIsEmpty: NO

struct
    This topic has been closed for replies.

    5 replies

    BKBK
    Community Expert
    Community Expert
    September 4, 2009

    More info on the issue

    <cfset structure = structNew()>
    <cfset customStruct = structNew()>
    <cfoutput>
    <cfloop list="form,url,customStruct" index="structType">
    <cfswitch expression="#structType#">
        <cfcase value="customStruct">
            <cfset structure = customStruct>
        </cfcase>
        <cfcase value="form">
            <cfset structure = form>
        </cfcase>
        <cfcase value="url">
            <cfset structure = url>
        </cfcase>
    </cfswitch>
    <h3>#structType#</h3>
    <p>
    #structType# not yet populated: <cfdump var="#structure#">
    </p>
    <cfset structure.myVar ="1">
    <p>
    #structType# populated: <cfdump var="#structure#">
    </p>
    <p>
    <cfset isDeleted = structdelete(structure,"myVar","true")>
    After implementing structdelete, structIsempty(#structType#):<cfdump var="#structisempty(structure)#"><br>
    <p>
    Dump of #structType# after implementing structdelete: <cfdump var="#structure#">
    <hr align="left" width="50%">
    </p>
    </cfloop>
    </cfoutput>

    September 4, 2009

    This is more good proof of the bug.

    What is very interesting to note is that the dumped structs for Form and URL at the end of the code shows an empty struct but the label doesn't indicate that it is like the custom struct does... "struct" vs. "struct [empty]". It's acting like there are hidden elements in there.

    Thanks for the code post, BKBK!

    Inspiring
    September 4, 2009

    cfcoder2 wrote:

    This is more good proof of the bug.

    How so?  It seems like the same issue to me. ie Assigning the variable just changes the variable reference to point to the FORM or URL objects. So it is essentially as if you were still using the FORM/URL objects.

    <h3>#structType#</h3>
    <cfoutput>#structure.getClass().name#<br></cfoutput>

    September 4, 2009

    OK I went ahead and filled out the bug report for CF9 Beta 1.

    I left build data out but stated there that it fails in CF8 (implying it's been around for a while)

    I did search to see if the bug had been previously reported and could not find any reports.  I searched on StructDelete, StructIsEmpty and URL.

    September 3, 2009

    Thanks for the comments and responses and for confirming my suspicions.

    Now if we can get Adobe to fix this anomoly in their code.  To me I agree that the behavior should conform to that of a struct for URL and Form. However they seem to act partially like a "read only" struct. Maybe there are ramifications to making it conform as a true struct but AT A MINIMUM, they should clearly document the behavior so that developers can quit wasting time over finding this bug out over and probably over again.

    Listening, Adobe???

    Inspiring
    September 3, 2009

    cfcoder2 wrote:


    Listening, Adobe???

    If you feel that strongly, make certain it IS in the bug database. If it is, cast your vote for that bug and add your comments. If it is not there, enter it as a new bug.

    September 4, 2009

    I am willing to submit this but the link provided in this thread is for CF9 beta.

    If there is a place to submit CF8 bugs I'll do it.  I tried the CF9 bug base and it does not list CF8 except for CF8.0.1 J which I assume is for Japan?

    Inspiring
    September 3, 2009

    From: cfcoder2

    In my case the URL has one key called "SN".  I delete it

    using StructDelete function.

    I then immediately test it for emptiness...using

    StructIsEmpty, but it displays No. Yet, a dump of the URL

    struct shows it is.

    What gives?????

    Technically, URL and FORM are not structures. The issue appears to be related to that fact. In the mean time, if you want the same behavior as with standard structures, use duplicate(). Then perform your operations on the copy.

    http://cfsearching.blogspot.com/2009/06/that-which-we-call-structure-by-any.html

    Inspiring
    September 3, 2009

    Your blog post is very interesting, and makes a good amount of sense.  But the fact remains that if CF exposes the underlying data structure as a struct, and struct functions "work" on it, then the results should conform to the expectations one would have based on the documentation of the relevant struct functions.

    --

    Adam

    Inspiring
    September 3, 2009
    But the fact remains that if CF exposes the underlying data structure as a struct, and struct functions "work" on it, then the results should conform to the expectations one would have based on the documentation of the relevant struct functions.

    --

    Adam

    Yes, I had mixed feelings on that when I wrote the entry.  It seemed like a bug. But for all I knew there was a good reason those scopes behaved the way they did. But on reflection, I agree with you.  Since it behaves "like" a structure in almost every other way, to break with the user expectations here is counter intutive.

    Edit:  But obviously there is no way to change the current behavior. Hence the suggestion of using duplicate();

    Inspiring
    September 3, 2009

    I get the same thing in CF8 & CF9.

    I would guess that it's structIsEmpty() that's bung.

    It seems specific to the URL scope... if one alters your code slightly to use a normal struct, everything works as one would expect.

    Do you wanna raise a bug with Adobe?

    http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#

    --

    Adam

    Inspiring
    September 3, 2009

    It seems specific to the URL scope... if one alters your

    code slightly to use a normal struct, everything works as

    one would expect.

     

    Do you wanna raise a bug with Adobe?

     

    http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#

     

    --

    Adam

    Check the bug database. It should already be there. (It also applies to the form scope.)