Am I misunderstanding something, or should I be ab...
# adobe
r
Am I misunderstanding something, or should I be able to have public static variables on a component? (I can get public static methods to work, but variables don't seem to be working for me)
I attempted:
Copy code
static {
  public foo = 'bar';
  public static.foo2 = 'bar2';
}
public static.foo3 = 'bar3';
But all attempts to reference them via
componentname::foo
componentname::foo2
componentname::foo3
error
r
I have the following working in production on CF2021 and testing on CF2025.
Copy code
component {
    static {
        public foo = "bar';
        public bar = "foo";
    }
}
r
Ugh. I did a simplified component locally and it works. Now to find out what's causing the issue.
Seems that static variables might not work if the component is a tag.
Copy code
<cfcomponent name="test">
  <cfscript>
  static {
    public foo = 'bar'; // This doesn't work
  }
  public static string function bar(){ return 'foo'; } //This still works
  </cfscript>
</cfcomponent>
test::foo
throws an error,
test::bar()
returns
foo
d
Ugh. Maybe ping @Mark Takata (Adobe), he'll probably know who has a definitive answer to whether that's supposed to work, and can raise a bug if it's busted.
Righteously tag vs script shouldn't matter, in any universe I'm aware of. Might be an artifact of how and when static was implemented.
m
@nimitsharma thoughts here?
n
@rodel30: Please share the exception stack trace that you are getting. Just wanted to check if you are also getting the same error.
v
@rodel30 It looks like this is broken in the Tag-based syntax. Could you please log a bug for this here? In the meantime, you can use the script-based syntax as a workaround.
r
I can only use the script based syntax if I rewrite the entire CFC into CFScript, yeah? (I don't think ACF has "tag islands")
d
You could probably do an include, but there's no guarantee the (mis?)behavior would be the same.
m
Script and tags share scope, but we don't have the same "tag island" thing as Lucee. So you could technically pop into a script in the middle of a bunch of tags, then go back. I will do that sometimes when tags feel like they're cleaner in views.
d
Could you make the component tag itself tag based, but have 99% of its code in a cfscript block, everything except the static declarations?
r
Is there a way to do tag based static declarations? Docs don't show it. Is there a
<static>
block that can have
<cfset public foo = 'bar'>
in it?
r
You could try
<cfset public static.foo = 'bar'>
instead of putting it in a static block.
r
Doesn't work, throws a syntax error.
v
@rodel30 Please let us know which version of ColdFusion you are currently using, so we can provide the appropriate patch for your setup
๐Ÿ‘ 1
r
We're on
2021,0,20,330407
Enterprise edition. We're utilizing the
hf202100-8888888.jar
for the unscoped variable reference logging as well, if that matters.
n
@rodel30: Kindly log the bug using the tracker portal: https://tracker.adobe.com/ for this issue and share the Bug ID here once itโ€™s created. Please reach out to @priyank_adobe to get the patch for this issue if required.
r
CF-4226965
Sorry, created the bug last week but didn't think to share the ID here.
๐Ÿ‘ 1
p
@rodel30 I will check this and get back to you.