tracker issue : CF-4203365

select a category, or use search below
(searches all categories and all time range)

The cfinclude attribute runonce not working inside components

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/Fixed

Reporter/Name(from Bugbase): Thomas Rafferty / ()

Created: 10/08/2018

Components: CFComponent

Versions: 2016,11.0,2018

Failure Type: Others

Found In Build/Fixed In Build: 11,0,12,302575 / CF2016U12,CF2018U5

Priority/Frequency: Normal /

Locale/System: / Windows 10 64 bit

Vote Count: 1

Problem Description:
 The error message "Routines cannot be declared more than once" is being shown for a function that is included twice with runonce="true" specified both times.

This problem does not occur using Lucee.

Steps to Reproduce:

Here is a short test case of 4 files that reproduces the problem.

<!--- /index.cfm --->
 <cfset createObject("component", "component").init()>
<!--- /component.cfc --->
 <cffunction name="init" output="true">
 <cfinclude template="file_that_depends_on_message.cfm" runonce="true">
 <cfinclude template="message.cfm" runonce="true">
 <cfset message("component")>
<!--- /file_that_depends_on_message.cfm --->
 <cfinclude template="message.cfm" runonce="true">
 <cfset message("file that depends on message")>
<!--- /message.cfm --->
 <cffunction name="message" output="true">
 <cfargument name="value" type="string">

Actual Result:
 The error message "Routines cannot be declared more than once."

Expected Result:
 "file that depends on message

Any Workarounds:
 Using cfscript, the function can be defined anonymously and assigned to a variable.
 variables.message = function(value)

{ writeOutput("#value#<br>"); }




I started using the "runonce" parameter now that we've upgraded most of our projects and I ran into this error too. So it 1) either doesn't work as documented or 2) I must have a different understanding of what "run once" means. I've been using this workaround since ColdFusion 8 and guess I'll continue to use it to prevent this compilation error from occuring. <CFPARAM NAME="Request.RunOnce" DEFAULT="0"> <CFSET Request.RunOnce = VAL(Request.RunOnce)+1> <CFIF val(Request.RunOnce) IS 1> <CFINCLUDE TEMPLATE="./Site_Specific_UDFs.cfm"> </CFIF> The "runOnce" feature was introduced in CF10. I see that it was reported in CF11 alpha. I encountered it in CF2016u10 as I figured two (2) release versions would mean that it would be safe to use. It has a "normal" priority with a "to fix" status. CF11 is EOL in 5 days (April 30, 2019). Are there any plans to fix this in CF2016, CF2018 or an unannounced, yet-to-be-released version?
Comment by James M.
30660 | April 25, 2019 03:44:36 PM GMT
I didn't know that this option existed, but encountered this bug the first time I used it.
Vote by James M.
30661 | April 25, 2019 03:48:12 PM GMT