onApplicationStart
# lucee
d
onApplicationStart
Copy code
component {
     public function onApplicationStart() {
        // runs
        createObject("java", "java.lang.System").out.println("!!!!!!!!!! on app start");
    }
}
Copy code
component {
    application.foo = 42;
    public function onApplicationStart() {
        // does not run
        createObject("java", "java.lang.System").out.println("!!!!!!!!!! on app start");
    }
}
Does writing to the application scope from the psuedoconstructor mean "don't run onApplicationStart"?
s
iiiiinteresting
I wonder if this happens in ACF as well?
r
The pseudo constructor runs on every request. The onApplicationStart method runs on the first request after server start up or after the application timeout. Application.foo should not be set in the pseudo constructor and will probably throw an error. It might be silently throwing an error which is then causing onApplicationStart not to fire.
d
Hm. In this case, the associated index.cfm runs, and
application.foo
, as seen from within index.cfm, is 42.
r
I can see it working if that value was added after the application started. I'd call it a bug if it worked on server start, but I don't know when the pseudo scope gets processed within the lifecycle events.
Either way it's bad practice to set an application scoped variable in the pseudo scope because that will run on every request.
d
Yes some kind of bug, or behavior difference from acf at least.