CFLint - Global Variable warning

200 Views Asked by At

I'm using the VS Code editor. And I have installed CFLint on my editor. On Application.cfc I see 'Identifier this is global, referencing in a CFC or function should be avoided.cflint(GLOBAL_VAR)' message when I mouse over into this scope.

Please explain this little bit elaborate. Thanks in advance.

1

There are 1 best solutions below

2
Alex On

The this scope in ColdFusion is equivalent to Java's public <type> <variable> declaration, a.k.a. "public fields". You can read and write these variables from anywhere, which is usually a bad thing (violates OOP encapsulation, is not thread-safe etc.).

This is also true for components (classes) in ColdFusion. However, the Application.cfc is a special case where this linter warning doesn't make any sense since "Application" is a singleton handled by ColdFusion and you cannot encapsulate it's configuration fields that reside in this.

Conclusion: Ignore this message in Application.cfc for all built-in fields, but follow it in every other .cfc file.

(You might want to report this to the linter's maintainer.)