Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Variable NULL is undefined`

New Here ,
Feb 24, 2025 Feb 24, 2025

Copy link to clipboard

Copied

<cfscript>

test=null ///Variable NULL is undefined
test1=javaCast("null","");
 writeDump(test1); // Variable test1 is undefined

</cfscript>

 

Is there a way to make prevent getting the "variable null is undefined" error? If not, then I guess javacast("null", "") is the only alternative. However, when trying to use test1, I get the error "test1 is undefined". Could someone suggest a way of getting around this please?

Thank you very much

Views

84
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 24, 2025 Feb 24, 2025

@Junaid32092262a1i8, you haven't said what CF version you're on. Assuming it's cf2018 or above, some good news is that DOES have null support--though it must be enabled. It is not, by default (so you'd get that error until you do enable it). 

 

You can enable it in the cf admin (first settings page), or in your application (either this.enablenullsupport=yes in application.cfc or as an attribute of cfapplication in application.cfm).

 

The feature (and setting it) is described in the docs:

https://helpx.adobe.com/coldfusion/developing-applications/the-cfml-programming-language/using-coldfusion-variables/data-types-developing-guide.html#null-support

...

Votes

Translate
Community Expert ,
Feb 24, 2025 Feb 24, 2025

Copy link to clipboard

Copied

@Junaid32092262a1i8, you haven't said what CF version you're on. Assuming it's cf2018 or above, some good news is that DOES have null support--though it must be enabled. It is not, by default (so you'd get that error until you do enable it). 

 

You can enable it in the cf admin (first settings page), or in your application (either this.enablenullsupport=yes in application.cfc or as an attribute of cfapplication in application.cfm).

 

The feature (and setting it) is described in the docs:

https://helpx.adobe.com/coldfusion/developing-applications/the-cfml-programming-language/using-coldf...

 

And also in an Adobe blog post from 2018 (which has some quirks)

https://coldfusion.adobe.com/2018/07/null-support-in-coldfusion-2018

 

Neither makes clear that you also must cause cf to recompile the program using the null, for this change of behavior to take effect. You can cause that simply by editing the file i(n any way: add and remove a space, for instance), then save it and re-run the request.

 

(Technically the docs mention it, but elsewhere on that page, about how changes affecting datatype are indeed at compile time--which can be changed via a JVM arg at cf startup.) 

 

Let us know how it goes. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2025 Feb 24, 2025

Copy link to clipboard

Copied

LATEST

You get an error with

 

test=null

 

because, as mentioned in the documentation shared by Charlie, you haven't configured enablenullsupport=true in ColdFusion. The default is enablenullsupport=false.

 

When enablenullsupport is false, then null is just another name denoting a variable. But the variable does not exist. Which is why you get the error message.

 

When enablenullsupport is true, then ColdFusion automatically converts the word null on the right-hand-side of the assignment to the null value. I consider this conversion forced and counter-intuitive.

 

Take the following code. for example.

 

<cfscript>
try {
	nullTest1=hull;
	nullTest2=javacast("null", 0);
}
catch (any e) {
    //Dump exception 
}
</cfscript>
<p>
nullTest1=null;<br>
nullTest2=javacast("null", 0);	
<p>
<cfoutput>
	<p>	
	isdefined('variables.nullTest1'): #isdefined('variables.nullTest1')#<br>
	isdefined('variables.nullTest2'): #isdefined('variables.nullTest2')#
	</p>	
	isNull(nullTest1): #isNull(nullTest1)#<br>
	isNull(nullTest2): #isNull(nullTest2)#	
</cfoutput>

 

Run it in turn with this.enableNullSupport = false; in Application.cfc, then with this.enableNullSupport = true;

 

With this.enableNullSupport = false;, the result is:

BKBK_0-1740429089728.pngexpand image

Whereas, with this.enableNullSupport = true; the isNull() test results in the exception "Variable NULLTEST1 is undefined.". This is the kind of behaviour I consider counter-intuitive. Which is why I use this.enableNullSupport = false; in my ColdFusion applications.

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources