Inability to refer to CFC's with static data in a dynamic way

Description

This is a re-open of an old issue raised by Ryan Guill (https://luceeserver.atlassian.net/browse/LDEV-255) regarding being able to dynamically call on static functions. The original ticket solved half of the problem Ryan had reported on (evaluating the right hand side of :: ) but did not resolve the left hand side.

Significantly, this code:

data = [ dynamicPath ]::getData();

throws a compile time error: Missing [;] or [line feed] after expression

In this code, `[ dynamicPath ]` should evaluate to `model.static`

I've included a .zip with a .cfm and a .cfc. Compile time errors are commented out individually in the .cfm code so you can test each case.

Use case is dynamically loading static data from possibly hundreds of CFCs in a dynamic way.

Workaround currently is to switch/case to static calls based on the passed in target CFC, which for hundreds of CFCs is daunting and not very maintainable.

Environment

Lucee 5.1.1.65 in CommandBox (Win7) and also as stand-alone in VM (Win2008)

Attachments

1

Activity

Julian Halliwell 
25 October 2018 at 16:29

: "i don't like the syntax of using [ ] on the left. we should consider something else."

Lucee currently supports instantiating components using dynamic paths using the New() keyword as follows:

myResult = New "#dynamicPath#"().myMethod();

Why not use the same syntax for static members?

myResult = "#dynamicPath#"::myStaticMethod();

Michael Offner 
27 March 2017 at 17:23

reduced priority of the ticket because https://luceeserver.atlassian.net/browse/LDEV-1254#icft=LDEV-1254 solves the blocking aspect of this ticket and provides a solution.

Michael Offner 
27 March 2017 at 14:59

i don't like the syntax of using [ ] on the left. we should consider something else.

do call Build in functions dynamically you can do the following:

ar=GetBuiltInFunction("ArrayLen"); dump(ar); dump(ar([]));

http://trycf.com/gist/891e4c3763f9d289c0ad73bb2af68349/lucee5?theme=monokai

maybe we should support the same for static component functions:

ar=GetStaticComponentFunction(compName,functionName); dump(ar); dump(ar([]));

we can do this implementation as first step to close the gap, because it is easy and fast to do and then as a second step discuss possibilities about a native synax for this.

Pothys - MitrahSoft 
8 March 2017 at 05:44

I've added test case for this ticket & confirmed that issue happened in latest version of lucee. If we try to access static data in via dynamic variable, it's not working. It works only when given as 'hardcode'

Pull Request: https://github.com/lucee/Lucee/pull/183

Details

Assignee

Reporter

Priority

Labels

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 3 March 2017 at 18:48
Updated 14 May 2025 at 11:54