Skip to main content
Known Participant
October 22, 2009
Answered

Strange Error...

  • October 22, 2009
  • 1 reply
  • 1951 views

Hey there

[RPC Fault faultString="Unable to invoke CFC - Local variable currentUserVO on line 26 must be grouped at the top of the function body." faultCode="Server.Processing" faultDetail=""]

<cffunction name="login" displayname="login" access="remote" output="false" >
               <cfargument name="userVO"  required="true"  type="CurrentUserVO">
                   
                   
                         <cfquery name="loginQuery" datasource="*">
                              SELECT * FROM user WHERE username= '#userVO.username#' AND password = '#userVO.password#'
                     </cfquery>
                                       
                         <cfloop query="loginQuery">                                                 
                              <cfset var currentUserVO=createObject("component","CurrentUserVO")>
                                                      
                              <cfset currentUserVO.username      = #loginQuery.username# >
                              <cfset currentUserVO.password      = #loginQuery.password# >
                              <cfset currentUserVO.firstname      = #loginQuery.firstname# >
                              <cfset currentUserVO.lastname      = #loginQuery.lastname# >
                              <cfset currentUserVO.id           = #loginQuery.id# >    
                              <cfset currentUserVO.mail           = #loginQuery.mail# >                   
                              <cfset currentUserVO.tel           = #loginQuery.tel# >                                                       
                                                                
                         </cfloop>    
                                                                             
                         <cfif isDefined("currentUserVO")>
                              <cfreturn #currentUserVO#>
                         <cfelse>
                              <cfreturn 'false'>
                         </cfif>    
     </cffunction>

In the past( on my local mashine) it works correctly. But i'll test it on a real server and that error occours.... Is the Script not correct? (I'm a FlashDeveloper and to sooo familiar with Coldfusion)

Greetings, Nico

This topic has been closed for replies.
Correct answer Adam Cameron.

Hi Nico

Well... what does the error message actually say:

Local variable currentUserVO on line 26 must be grouped at the top of the function body.

And this is line 26:

<cfset var currentUserVO=createObject("component","CurrentUserVO")>

If you have a look at you other <cfset> statements, you'll see the difference here is the VAR keyword.

So, what do the docs say about the VAR keyword:

http://livedocs.adobe.com/coldfusion/8/htmldocs/buildingComponents_29.html

(I found this page by looking up VAR in the index of the docs):

"You must define all function local variables at the top of the function definition, before any other CFML code; for example: [etc]"

So your problem is that that VAR statement is NOT at the top of the function, as per the docs and the error message.

As to why it might have worked for you before?  This restriction of where VAR statements go has been removed from CF9.  So if you were using CF9 before, your code would have compiled OK.  But not on CF6.1->CF8.

Make sense?

--

Adam

1 reply

Adam Cameron.Correct answer
Inspiring
October 22, 2009

Hi Nico

Well... what does the error message actually say:

Local variable currentUserVO on line 26 must be grouped at the top of the function body.

And this is line 26:

<cfset var currentUserVO=createObject("component","CurrentUserVO")>

If you have a look at you other <cfset> statements, you'll see the difference here is the VAR keyword.

So, what do the docs say about the VAR keyword:

http://livedocs.adobe.com/coldfusion/8/htmldocs/buildingComponents_29.html

(I found this page by looking up VAR in the index of the docs):

"You must define all function local variables at the top of the function definition, before any other CFML code; for example: [etc]"

So your problem is that that VAR statement is NOT at the top of the function, as per the docs and the error message.

As to why it might have worked for you before?  This restriction of where VAR statements go has been removed from CF9.  So if you were using CF9 before, your code would have compiled OK.  But not on CF6.1->CF8.

Make sense?

--

Adam

maeldanusAuthor
Known Participant
October 22, 2009

Ah... I've tried it with COldfusion 9 but our Server runs on Coldusion8 ....

But, i have to create a instance of that var for each user in the db - in the querryloop. How can i solve that problem?

Inspiring
October 23, 2009

Ah... I've tried it with COldfusion 9 but our Server runs on Coldusion8 ....

But, i have to create a instance of that var for each user in the db - in the querryloop. How can i solve that problem?

That's fine. One you've declared a variable to be function-local (using the VAR statement), it stays function-local for the life of the function.  You don't have to re-state that it's function-local every time you use it.

So initialise it as a VAR @ the top of the function, then use it as per normal thereafter.

Make sense?

--

Adam