There are two things to consider when defining a scope:
- readability
- Bleeding and performance
For both reasons, I would (generally) recommend you to cover all areas of application both in the CFC class and outside it. You will never be surprised at the results if you do this. However, these are two different cases:
Inside CFC:
ALWAYS a Variables region, since it is a "protected" region shared between methods and the body of the class. And use it only when you are very sure that you want to use it. You can use it as a property element for instantiated classes, but be very careful if you use it in a singleton class (cached in the Application scope). This can lead to unintentional bleeding. In addition, if there are any external variables with the same name, you can again inadvertently pull them out of thin air. Not what you want. In addition, the uncertainty of the Variables region in CFC is confusing since there are local var values that do not accept the region prefix. Just the Variables area is here if you use it here.
Outside of CFC:
You can allow yourself to not cover Variables on the CFM / include page, as long as it is clear, imho. Efficiency does not have to be effective since CF will check this FIRST area (outside of CFC). My general preference is that I first install / declare it, and then, if it is clear and in a visual context, leave it without access. If the page is very long or I broke the page (for example, a long report, for example) into pieces (including), I will definitely make it prefix again, so it’s very clear where it comes from. If I consistently cover all other areas (which I recommend), it should be clear that unscoped is Variables , but I like it. In particular, if other people are also working on a codebase. Therefore, if it is not clear, open it. Good rule of thumb.
Search Order:
Finally, I hate it when people talk about search order and then mix CFC and page areas. Keep in mind that they are different, and CF did not document them very well or clearly ( Local and var are equal "where the last time wins, Arguments will be found before Local in CFC, when undeclared or overloaded, Variables and Property also mixed). On the page (CFM / include template), the Variables area is the default and the search is performed first. The exception is the request area in the context of the request block. Again, they are not very well documented, and in CF we don’t always think of block coverage, as in some languages but it really is. Out of context of request expect Variables Variables for trump cards. If you are not sure about this, check it out or check it. Also keep in mind that the this , Request , Application and Session fields are not executed if the CF encounters a non-prefix variable.