Skip to main content
Known Participant
July 5, 2012
Question

variable scope in a cffunction

  • July 5, 2012
  • 2 replies
  • 773 views

Is there a scope that would allow a variable set in a cffunction to be visible to the cfm file that calls it, similar to the caller scope used in custom tags?  This is not including the return value of the cffunction.

I am trying to set a few variables in the OnRequestStart method of my application.cfc file, but these variables are not visible to the pages in the application.

This topic has been closed for replies.

2 replies

Inspiring
July 5, 2012

To answer your question literally: no, but you could pass a reference to a struct into the function as an argument, and change the keys in the struct in the function, and those changed keys will then be available in the calling code.

However ths will not solve your particular issue, because onRequestStart() is not called from your code, it's called by CF.

What you need to do is to set request-scoped variables.  That'd be be best fit for variables set in onRequestStart(), I think.

--

Adam

Known Participant
July 5, 2012

Thank you both for your assistance.

I will use the request scope.  I was hoping for something special like the caller scope in custom tags.

Richard

Inspiring
July 5, 2012

Either session or request might suit your needs.