Spec-Zone.ru › ColdFusion

isDefined

Evaluates a string value to determine whether the variable named in it exists.

isDefined(variable_name) → returns boolean

  • CF3+
  • Lucee
  • BL 1.0.0+
  • See Also: structKeyExists isEmpty ArrayIsDefined

    Argument Reference

    variable_name string
    Required

    A string expression containing the name of a variable to check the existence of. Only simple dotted notation is supported (for example myVar, arguments.myArg, myStruct.key). Square bracket notation to reference array elements or struct keys is not supported.

    Links more information about isDefined

    • structKeyExists() vs isDefined() - An Adobe Forums discussion on the differences between structKeyExists() and isDefined().
    • Variable Naming Rules - Adobe Documentation defining valid variable names

    Examples
    Sample code invoking the isDefined function

    Using IsDefined

    Checking for the existence of a form variable.

    <cfif isDefined("form.submit")>...</cfif>

    Scope Evaluation Order and Unscoped Variables

    Beware of scope evaluation order when checking for an unscoped variable name.

    url.foo = "url.foo" ; form.foo = "form.foo"; writeoutput("Is 'foo' defined? " & isDefined("foo")); writeoutput(isDefined("foo") ? " (" & foo & ")" : "");

    Expected Result: Is 'foo' defined? YES (url.foo)

    Dot-notation Variable Names

    Potentially unexpected behavior when checking for a dot-notation variable containing a scope name.

    local["form.submit"] = "local['form.submit']" ; form.submit = "form.submit"; writeoutput("Is 'form.submit' defined?" & isDefined("form.submit")); writeoutput(isDefined("form.submit") ? " (" & form.submit & ")" : ""); writeoutput("<br>"); writeoutput("Is 'submit' defined? " & isDefined("submit")); writeoutput(isDefined("submit") ? " (" & submit & ")" : "");

    Expected Result: Is 'form.submit' defined? YES (local['form.submit']) Is 'submit' defined? YES(form.submit)

    © 2012–present Foundeo, Inc. and the CFDocs contributors.
    Licensed under the MIT License.
    ColdFusion is a trademark of Adobe Systems Incorporated.
    https://cfdocs.org/isdefined

    Spec-Zone.ru

    Настройки Оффлайн Что нового Помощь О нас
    Spec-Zone .ru
    спецификации, руководства, описания, API