A ColdFusion user pinged me today with an odd problem. Whenever he was inside a CFC method (err, his code) and he called a private CFC method, he would get an access error. I asked him how we was calling his methods, and he said:
<cfset foo = this.someMethod()>
The problem is the use of "this." It is not needed when calling methods in the same CFC. You can simply do:
<cfset foo = someMethod()>
You can also use cfinvoke if you want.
So I'm pretty sure I posted this in the past, but I've seen it a few times recently so I hope folks don't mind the recyling.
Archived Comments
Err, Ray...
Don't you still need the () as <cfset foo = someMethod() />?
By the way:
Bonne Fete A Toi,
Bonne Fete A Toi,
Bonne Fete A Ray...
Bonne Fete A Toi.
It was a test to see if you were paying attention - I swear! :)
Yeah, the "this" scope is basically what external objects see, as in <cfreturn this> on an init() method. It's the same object you get when you just create the object, so you won't see any private methods in "this".
If you feel the need to scope your local method calls, use the variables scope.