Charles Robertson
01/20/2023, 11:03 AM<cfinclude />
When creating cross cfml engine [ACF/Lucee] compatible code.
For instance, if you do something like this, you will get a compilation error:
function GetFrameworksByParam() {
var local = {};
local.frameworkbyparam = {
var1 = "hello world"
};
local.szResponse = {};
if(server.keyExists( 'lucee' )){
local.serializeParam_lucee_object = local.frameworkbyparam;
local.serializeResponse_lucee = Serialize(local.serializeParam_lucee_object);
local.szResponse = local.serializeResponse_lucee;
}
else{
local.serializeParam_acf_object = local.frameworkbyparam;
local.serializeParam_acf_type = "xml";
local.szResponse = Serialize(local.serializeParam_acf_object, local.serializeParam_acf_type);
}
WriteDump(var=local.szResponse);
}
GetFrameworksByParam();
The error occurs because of there are differences between the amount of params that the native method:
Serialize()
Can accept.
In ACF, it is two params, whereas in Lucee, it is just one param.
Differences in param names, if the params are named within the method call, also cause errors.
The compiler checks code in every conditional branch.
But, if you hide the code in an include, there is no error:
function GetFrameworksByParam() {
var local = {};
local.frameworkbyparam = {
var1 = "hello world"
};
local.szResponse = {};
if(server.keyExists( 'lucee' )){
local.serializeParam_lucee_object = local.frameworkbyparam;
include "includes/serialize-lucee.cfm";
local.szResponse = local.serializeResponse_lucee;
}
else{
local.serializeParam_acf_object = local.frameworkbyparam;
local.serializeParam_acf_type = "xml";
include "includes/serialize-acf.cfm";
local.szResponse = local.serializeResponse_acf;
}
WriteDump(var=local.szResponse);
}
GetFrameworksByParam();
includes/serialize-lucee.cfm
<cfset local.serializeResponse_lucee = Serialize(local.serializeParam_lucee_object) />
includes/serialize-acf.cfm
<cfset local.serializeResponse_acf = Serialize(local.serializeParam_acf_object, local.serializeParam_acf_type) />
Am I correct in thinking that CFML application servers don't check code within cfinclude , at compile time?zackster
01/20/2023, 11:05 AMCharles Robertson
01/20/2023, 11:06 AMzackster
01/20/2023, 11:06 AMCharles Robertson
01/20/2023, 11:11 AMzackster
01/20/2023, 11:15 AMCharles Robertson
01/20/2023, 11:20 AMcfinclude, by the compiler, but that the compiler does check other code constructs inside a cfincludezackster
01/20/2023, 11:20 AMCharles Robertson
01/20/2023, 11:22 AMcfinclude πzackster
01/20/2023, 11:22 AMCharles Robertson
01/20/2023, 11:22 AMzackster
01/20/2023, 11:23 AMCharles Robertson
01/20/2023, 11:23 AMzackster
01/20/2023, 11:23 AMCharles Robertson
01/20/2023, 11:27 AMzackster
01/20/2023, 11:27 AMCharles Robertson
01/20/2023, 11:28 AMso in the good old early days of cfmlAnd you can't do that now?
zackster
01/20/2023, 11:29 AMCharles Robertson
01/20/2023, 11:32 AMvar imgFormats = evaluate("imageFormats( true )"); // v2, evaluate to bypass compile error with v1zackster
01/20/2023, 11:32 AMzackster
01/20/2023, 11:32 AMCharles Robertson
01/20/2023, 11:33 AMlocal.szResponse = evaluate("Serialize(local.serializeParam_acf_object, local.serializeParam_acf_type)");zackster
01/20/2023, 11:34 AMCharles Robertson
01/20/2023, 11:35 AMCharles Robertson
01/20/2023, 11:36 AMzackster
01/20/2023, 11:38 AMarrayLen(getFunctionData("serialize").arguments)Adam Cameron
/shims/
lucee/
Shims.cfc
CF/
Shims.cfc
On lucee map /shims to /shims/lucee, and one CF map /shims to /shims/CF
And in yer app use Shims::serializeAdam Cameron
Adam Cameron
Adam Cameron
bdw429s
01/20/2023, 6:34 PMattributeCollection when it comes to tags with differing attributes per engine.
https://github.com/coldbox-modules/s3sdk/blob/development/models/AmazonS3.cfc#L1410-L1413Charles Robertson
01/20/2023, 9:10 PMbdw429s
01/20/2023, 9:15 PMzackster
01/21/2023, 8:44 AMAdam Cameron
Charles Robertson
01/21/2023, 2:45 PMCharles Robertson
01/21/2023, 2:47 PMOne thing to note: BIFs implemented in CFML are compatible with, while those implemented in Java are not.argumentCollection
Thanks for that nugget, @Ryan GuillBut, having looked at the link [BIFs implemented in CFML]: https://github.com/lucee/Lucee/tree/master/core/src/main/java/resource/library/function It doesnβt seem to do what the comment is describing. These functions use the attribute collection of the functionβs tag equivalent. But you cannot pass the params in via the argumentCollection param, except for
queryExecute(), which allows you to use an options param to do so.
So, the answer is, currently, no.
But it could be a Lucee feature, in the near future? π€