-1

I'm trying to modify existing codes in my ColdFusion application left by previous programmer. I don't understand the meaning of this line of code (the one with question marks):

      <cfset Application[#form.username#] = 0> ??????
      <cfset Session.loggedin="Yes">
      <cfset Session.username="#Trim(Form.username)#">

Maybe I haven't been working with CF long enough to see this syntax so I don't know what this mean. When setting an application variable I usually use this syntax:

      <cfset application.variableName = "some value"> 

Can someone explain to me what is this ? Thank you

user3476679
  • 53
  • 1
  • 5
  • The brackets look like they might be just an alternate array syntax (similar to other languages' use). If `form.username` was `ceejayoz` I believe it'd be looking up the setting `Application.ceejayoz` - probably intended for some sort of multi-tenant system. The # characters: http://stackoverflow.com/questions/21564218/when-and-when-not-to-use-hash-symbol-in-coldfusion – ceejayoz Feb 04 '15 at 19:44

1 Answers1

0

As well as explicitly stating variable names at "code time" with dot notation, CFML allows one to reference them dynamically at runtime via a string value.

This is done via associative array notation (using square brackets), eg:

myVariableName = "foo";
variables[myVariableName] = "moo"; // equivalent to variables.foo = "moo"
Fish Below the Ice
  • 1,273
  • 13
  • 23
Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
  • Respond to Adam: Thanks for your comment but I did not google it first because this code appear in the middle of no where. There is no indication from the whole template or the next template that there is an array to be set or to be used. I thought that code referred to something that I don't normally use and know. – user3476679 Feb 05 '15 at 14:35
  • By the way, it is written in CF8 and the application is poorly written. It's not in my nature to ask someone to search for the answer without doing it myself, forum is usually my last resort. – user3476679 Feb 05 '15 at 14:42
  • I don't see how any of that would prevent you from googling the first three words what probably popped into your mind when you saw it (well, not the "WTF is *that*?", but the next three words ;-). But never mind. – Adam Cameron Feb 05 '15 at 15:13
  • That's it, it did not popped up in my head that those syntax referred to an array. – user3476679 Feb 05 '15 at 15:29
  • @fish-below-the-ice pls revert your change to my answer. *Googling* for information like this probably the most useful advice anyone reading this question and answer could be given. If you have an issue with something someone says, you should *talk to them*, not simply delete their stuff. That's a really poor & unhelpful attitude to take. – Adam Cameron Feb 05 '15 at 19:53
  • 1
    @user3476679 like I said... I didn't google anything about arrays. I googled "coldfusion variable brackets". You can't say none of those words seemed immediately significant, given you're looking at *ColdFusion* code, it's a *variable* (am assuming you realised that), and you were wondering what the *brackets* were all about! – Adam Cameron Feb 05 '15 at 19:54
  • 5
    This answer is currently being discussed on meta: http://meta.stackoverflow.com/q/285464/1159478 – Servy Feb 05 '15 at 20:10
  • 11
    Adam: I think @Servy is commenting here as a courtesy to you, and to give you the right of reply. He did not start that conversation. – halfer Feb 05 '15 at 21:22
  • 7
    (For what it's worth, I would edit that commentary out too. Aside from the reasons in the Meta discussion, posts should be written for a general audience, and whether a question should have been searched for is too localised to the OP. It would probably be better as a comment under the question). – halfer Feb 05 '15 at 21:24