Deepak Kumar Padhy
Deepak Kumar Padhy

Reputation: 4388

What is the difference between THIS scope and APPLICATION scope in ColdFusion?

Today I was reading a blog Difference between THIS and APPLICATION scope. What explained their I understood , After that i declared a variable in my Application.cfc in THIS scope, I am able to access that variable in all of my pages. So my question is Can we use THIS scope for declaring application level variables? OR Is there any more difference between THIS and APPLICATION scoped variables. Example: Application.cfc

<cfset THIS.testVar1 = 50>
<cfset APPLICATION.testVar1 = 100>

Index.cfm

<cfdump var="#THIS.testVar1#"> O/P: 50
<cfdump var="#APPLICATION.testVar2#"> O/P: 100

So this leads to think me that both the scopes are similar. Please let me know if something more difference is there between these scopes.

Upvotes: 1

Views: 2517

Answers (1)

Henry
Henry

Reputation: 32905

This scope in Application.cfc is for setting cf application settings and shall be read using https://wikidocs.adobe.com/wiki/display/coldfusionen/GetApplicationMetadata in cf10.

This scope for ordinary cfc is for storing public functions and public attributes.

Application scope is for storing and fetching pieces of data, usually app configs and instance of singletons. It lives until the cf application timeout, or stopped, or server restarted.

Upvotes: 2

Related Questions