Copy link to clipboard
Copied
How to prevent/detect the incorrect direct use of properies in cf9 e.g.
aPerson.FirstName = "Rumplestiltskin";
...when a component is rewritten to use accessors e.g.
aPerson.setFirstName("Rumplestiltskin");
e.g. a component is changed from...
Component Person {
property name="FirstName" type="string";
}
...to...
Component Person accessors="true" {
property name="FirstName" type="string" getter="true" setter="true";
}
1) Is it possible to prevent the propeties being set directly?
e.g. This should cause an error:
aPerson.FirstName = "Rumplestiltskin";
In practice, properties can still be set directly even though the component has declared that accessors should be used. I want to make this illegal im my app.
2) Is it possible to prevent the use of undeclared properties?
e.g. This should cause an error:
aPerson.ChristianName = "Rumplestiltskin"; // non-existent property
or
aPerson.furstname = "Rumplestiltskin"; // Mis-spelt property
In practice, properties can be set even if they don't exist. I want to make this illegal im my app.
3) Is it possible to intercept the direct use of properties
e.g. when this is executed...
aPerson.FirstName = "Rumplestiltskin";
..the function aPerson.setFirstName() is called
This would make it possible to solve 1), or better still, make the app backwardly compatible.
When an app is rewritten to use accessors, I don't want to have to change every instance of
aPerson.FirstName = "Rumplestiltskin";
...to...
aPerson.setFirstName("Rumplestiltskin");
...or at least, I want to be told if I've missed one.
Thanks,
Julian
Copy link to clipboard
Copied
Hi
Is that what you can reproduce at your end ? If yes then please provide below information:
1. Test case with the code to reproduce the error.
2. Server settings summary
3. Environment such as Operating system details, Web Server details.
Swaraj
Copy link to clipboard
Copied
Hi AlbusTeck
I'm using cf9.0.0 with IIS7 on Windows 7.
I'll post server settings in a seperate reply.
Code sample follows:
testcomponent.cfc:
Component testComponent accessors="true" {
property name="FirstName" type="string" getter="true" setter="true";
}
testcomponent.cfm:
<cfscript>
person = createObject("component", "testComponent");
writeOutput("<h1>1) Setting property directly doesn't cause an error, even though accessors should be used</h1>");
person.FirstName = "Rumplestiltskin";
writeOutput("person.FirstName returns: #person.FirstName#<br/>");
writeOutput("<h1>2) Setting undefined property directly doesn't cause an error</h1>");
person.Whatever = "Wah?";
writeOutput("person.Whatever : #person.Whatever#<br/>");
</cfscript>
Copy link to clipboard
Copied
System Information | ||||||||||||||
|
JVM Details | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Printer Details | |
Default Printer | |
Printers | Microsoft XPS Document Writer Fax |
Server Information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Debugging & Logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Schedule Tasks & Probes | ||||
|
Extensions | ||||||||||||||
|
Event Gateways | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Security | ||||||||||||||||
|
Copy link to clipboard
Copied
Hi Swaraj
> Is that what you can reproduce at your end?
Are you saying that using an undefined property should raise an error?
Thanks,
Julian