Uploaded image for project: 'Railo'
  1. Railo
  2. RAILO-2580

?.: safe navigation operator

    XMLWordPrintable

    Details

    • Type: Feature Request
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Out of Date
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      See http://cfmlblog.adamcameron.me/2013/08/thinking-about-operators-in-cfml.html

      This is best demonstrated with an example:

      a = {
      	b = {
      		c = {
      			d = 1
      		}
      	}
      };
      writeOutput(a?.b?.c?.d); // 1
      writeOutput(a?.e?.c?.d); // null
      writeOutput(a.e.c.d); // ERROR
      

      So rather than erroring because a.e doesn't exist, it gracefully returns null. Nice. This saves a lot of sequential structKeyExists() calls, or (grim) an isDefined() call.


      Adam

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                micstriit Michael Offner
                Reporter:
                adamcameroncf Adam Cameron
              • Votes:
                4 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: