Tim Blair
Private CFC methods and "this" (01/09/2003)
One common misconception in CFMX developers who started life in the Java world is that CFCs work the same as java objects. This of course is not true, but the changes can sometimes be very subtle.
An example of this can be found in the use of the "this" scope. In Java, a call to this.myMethod() makes the request "inside" the instance. Within a CFC the behviour is different: a call to this.myFunction() applies the function call from "outside" the instance, as if you had instantiated the object externally and are now calling the function on it.
The problem with this difference is that if you have a private function in a CFC and call that method from within the CFC (as you would) then if you call this.myFunction() you will recieve a function-not-found error, exactly the same as you would from attempting to call a private method from outside the CFC.
The same is also true using package-access functions when the calling script is outside the "package" of the CFC. If the CFC and the calling CFM page are in the same directory then using this.myFunction() will succeed; if the calling script is not in the same package then it will fail as above.
Article Archive (September '03 – '05)
- Private CFC Methods and "this" 01/09/2003
- Active Sessions Across CF Applications 12/09/2003
- isnumeric() - Too Clever for It's Own Good? 15/03/2004
- Modifying Page Generated Content 15/03/2004
- CF and Arrays of Basic Java Types 17/03/2004
- Writing UTF-8 Text Files with ColdFusion 13/05/2004
- Top vs. Bottom Posting 09/07/2004
- Local (var) Scope Shortcut 27/12/2004
- Using Apache mod_headers to Change Downloaded Filenames 16/06/2005
- Changing the Working Directory of
<cfexecute>12/07/2005 - Flickr Workshop Review 29/09/2005