A coupla questions about static usage / behaviour

Copying these from the slack channel as didn’t get much of a reaction there.

Is there any practical difference between either of these:

// Foo.cfc
component {
	static {
		Foo::someVar = 0
	}
}
// Foo.cfc
component {
	static {
		static.someVar = 0
	}
}

Or, that said, any idiomatic preference for one or the other?


Second question (it’s actually more than one question, now that I’ve finished typing it…) on how static properties are handled.

My expectation is that the “class” that a static property is a property of is unique to the JVM. So if I have a CFC at /path/to/My.cfc, and it has a static property, then all code running on that entire JVM would be using the same path.to.My class?

I am seeing two different requests on not only the same JVM but running in the same Lucee instance having two different versions of the same “class”. If I update the static property in one (eg: My::someVar = "new value" , I do not see the change in the other request.

I am seeing another variant where I access My::someVar for reading (eg: someOtherVar = My::someVar , Lucee says "nup, someVar doesn’t exist. Yet I run another request that has writeOutput(My::someVar) , and that outputs its value.

If these were objects I’d check their hashcodes expecting them to be different objects cos I’ve done something daft and accidentally created two objects. But there’s no equivalent daftery I can perform with static properties. And also I have no idea how I might get some sort of hashcode or ID from a CFC name anyhow. Is there a way of identifying which My my code is using, to check if somehow I have two of them?

NB: there are not different mappings in play here, all references are via the file-system path from the Lucee web root.

We don’t use static properties a lot in this app, but the few we use have always behaved fine in the past. One twist here is that I am changing the value of the static property (it’s part of a test, I would not normally do this). This should not matter though, as far as I know?

Cheers.


Adam

Interesting … the :: is new to me … I’m unlikely to be of help.
Thought I’d link a couple related docs in case I’m not the last to learn, and perhaps it will help encourage others respond.

Re: hashCode … there is this gem which may give some insight?

Doc:

Cookbook:

Good luck, I’ll be watching for the solution. :face_with_monocle:

1 Like