Baz,
That's actually just the way that onMM() works.
Firing a method from inside a CFC won't trigger the onMissingMethod()
call if it doesn't exist. Only calls from outside the instance, and
as you put it, on the 'this' scope fire the onMM.
The only workaround is to use a this.methodname() approach to fire the onMM.
Mark
On Jan 9, 2008 10:45 AM, Baz <[EMAIL PROTECTED]> wrote:
> If you mixin onMissingMethod() into a new object, then try to call some
> nonExistentMethod() from within your new object, the onMissingMethod()
> function does not get invoked and an error is thrown. However if you scope
> that method call with the "THIS" scope: THIS.NonExistentMethod() it works
> again. And if you call a missing method from another file outside the object
> it works too. So basically the issue arises while trying to invoke a non
> existent method through the "VARIABLES" scope. Is this normal and expected?
> Has anyone seen this before? I know that if the onMissingMethod() was coded
> directly into the CFC and not mixed in, this would not cause an issue.
>
> Here is my test case:
>
> I have 2 components:
>
> Mixin.cfc
> Object.cfc Mixin.cfc simply contains the onMissingMethod() function:
>
> <cfcomponent>
> <cffunction name="onMissingMethod" output="true">
> <cfreturn arguments />
> </cffunction>
> </cfcomponent>
>
> Object.cfc contains 2 functions, one to perform the mixin (a la Corfield)
> and one for testing:
>
> <cfcomponent>
> <cfscript>
> function mixin() {
> var target = createObject("component",'test.mixin.mixin1');
> structAppend(this,target);
> structAppend(variables,target);
> }
> </cfscript>
>
> <cffunction name="testMissingMethod">
> <cfreturn NonExistentMethod() />
> </cffunction>
> </cfcomponent>
>
> And lets say we have a third file index.cfm for testing these components:
>
> <!--- create object --->
> <cfset ObjectInstance=createobject('component', 'test.mixin.cfc1') />
>
> <!--- mixin onMissingMethod() --->
> <cfset ObjectInstance.mixin() />
>
> Now here's the weirdness.
>
> If you try to call a non-existent method from the index.cfm everything works
> fine:
>
> <cfdump var="#ObjectInstance .someRandomMethodName()#"> (success,
> onMissingMethod() is invoked)
>
> However, if you try to call a missing method from within the object itself,
> the following error is thrown "Variable ZIZI is undefined":
>
>
> <cfdump var="# ObjectInstance .testMissingMethod ()#"> (error)
>
> Now if you modify the testMissingMethod() function slightly by scoping the
> method call with "this", like so:
>
> <cffunction name="testMissingMethod">
> <cfreturn THIS.NonExistentMethod() />
> </cffunction>
>
> The function works again:
>
> <cfdump var="# ObjectInstance. testMissingMethod()#"> (success, now it
> works because we scope the inner method call with "THIS")
>
> Cheers,
> Baz
>
>
>
>
>
>
>
>
> >
>
--
E: [EMAIL PROTECTED]
W: www.compoundtheory.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CFCDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---