Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Created April 22, 2022 23:57
Show Gist options
  • Save adamcameron/38083f39b0c4d15c3af38075d695695c to your computer and use it in GitHub Desktop.
Save adamcameron/38083f39b0c4d15c3af38075d695695c to your computer and use it in GitHub Desktop.
Showing how CF doesn't respect imports for extends attributes
component {
loadMappings()
private void function loadMappings() {
thisDirectory = getDirectoryFromPath(getCurrentTemplatePath())
this.mappings["/mine"] = "#thisDirectory#myApp"
this.mappings["/theirs"] = "#thisDirectory#theirLib"
}
}
import theirs.TheirBase
component extends=TheirBase {
function f() {
var fromBase = super.f()
return "from MySub: #fromBase#"
}
}
component extends=theirs.TheirBase {
function f() {
var fromBase = super.f()
return "from MySub: #fromBase#"
}
}
<cfscript>
import mine.MySubUsingImport
import mine.MySubUsingQualified
import theirs.TheirBase
try {
writeOutput("Using import for creating TheirBase<br>")
theirBase = new TheirBase()
writeOutput(theirBase.f())
} catch (any e) {
writeDump([
message = e.message,
detail = e.detail
])
}
writeOutput("<hr>")
try {
writeOutput("Using import for extexding TheirBase<br>")
mySubUsingImport = new MySubUsingImport()
writeOutput(mySubUsingImport.f())
} catch (any e) {
writeDump([
message = e.message,
detail = e.detail
])
}
writeOutput("<hr>")
try {
writeOutput("Using fully-qualified path for extexding TheirBase<br>")
mySubUsingImport = new MySubUsingQualified()
writeOutput(mySubUsingImport.f())
} catch (any e) {
writeDump([
message = e.message,
detail = e.detail
])
}
writeOutput("<hr>")
</cfscript>
component {
function f() {
return "from TheirBase"
}
}
@adamcameron
Copy link
Author

File structure should be:

.
├── Application.cfc
├── myApp
│   ├── MySubUsingImport.cfc
│   └── MySubUsingQualified.cfc
├── test.cfm
└── theirLib
    └── TheirBase.cfc

Run test.cfm

Works fine on Lucee.

On CF:

Using import for creating TheirBase
from TheirBase
---
Using import for extexding TheirBase
struct (ordered)
MESSAGE	Could not find the ColdFusion component or interface TheirBase.
DETAIL	Ensure that the name is correct and that the component or interface exists.
---
Using fully-qualified path for extexding TheirBase
from MySub: from TheirBase

Expected: should bloody work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment