Nick
10/28/2024, 3:18 AM<cfscript>
Dog = new Dog();
test = Dog.doesItHavePaws();
</cfscript>
Dog.cfc:
component accessors="true" extends="Pet" {
function init() {
super.init();
return this;
}
boolean function doesItHavePaws() {
var result = variables.hasPaws;
writeOutput( "result: " & result );
return result;
}
}
Pet.cfc:
component accessors="true" {
property name="hasPaws" type="boolean" default="true";
function init() {
return this;
}
}
The result is an error: Element hasPaws is undefined in Variables.
However, if I add a writedump(Dog) in test.cfm, it shows the dump, and the function works fine, outputting my result.
<cfscript>
Dog = new Dog();
writedump(Dog);
test = Dog.doesItHavePaws();
</cfscript>
Alternatively, I can use getHasPaws() in the doesItHavePaws() method (instead of variables.hasPaws) and that works. From what I've read, though, variables is private to the CFC, but that's where I'm accessing it. And what would an external call to writedump() the object do that would make the default of the property suddenly work fine?
Also, this seems to be related to the extended component's properties only. If I move the property into Dog(), variables.hasPaws works fine.cfsimplicity
10/28/2024, 12:25 PMNick
10/28/2024, 12:33 PMcfsimplicity
10/28/2024, 12:52 PMCage S
10/28/2024, 2:16 PMNick
10/28/2024, 2:19 PMcfsimplicity
10/28/2024, 2:46 PMmappedSuperClass
was just for ORM entity inheritance.Nick
10/28/2024, 2:47 PMNick
10/28/2024, 2:47 PMlazy="false"
on the property, but no luck.Nick
10/28/2024, 2:47 PMbdw429s
10/28/2024, 9:53 PMbdw429s
10/28/2024, 9:54 PMinit()
to be sure.bdw429s
10/28/2024, 9:54 PMbdw429s
10/28/2024, 9:55 PMNick
10/28/2024, 9:58 PMNick
10/28/2024, 9:58 PMMatt Jones
10/29/2024, 1:54 PMbkbk
11/03/2024, 12:27 PMproperty name="hasPaws" type="boolean" default="true";
implies that Pet.cfc implicitly contains the methods getHasPaws()
and setHasPaws(true)
, with variables.hasPaws=true;
being implicitly defined in the setter.bkbk
11/03/2024, 1:05 PMproperty name="hasPaws" type="boolean" default="true";
implies that Pet.cfc implicitly contains the methods getHasPaws()
and setHasPaws(true)
, with variables.hasPaws=true;
being implicitly defined in the setter.
The getter and setter are of course inherited by Dog. However, variables.hasPaws
is a private variable in Pet.cfc. As such, it cannot be inherited by Dog, and so is distinct from the variables.hasPaws
in Dog.cfc.bkbk
11/03/2024, 1:11 PMstruct function getVariables(){
return variables;
}
Then run the following on the test page:
<cfscript>
myPet = new Pet();
myDog = new Dog();
writedump(var="#myPet.getVariables()#", label="myPet.getVariables()");
writedump(var="#myDog.getVariables()#", label="myDog.getVariables()");
</cfscript>
You will see that variables.hasPaws
is defined in myPet, but not in myDog.