Skip to main content
I.am.Sceiffer
Participating Frequently
Sep 19, 2021 10:47 PM UTC
Answered

the component function with visibility problem persists

It has looked like the problem was solved at CF 2021. After the 2nd. update, the same problem come back!

 

I've created a simple component containing a private and a public function.

 

component{
    private numeric function f_private(){
        return 12345;
    }

    public struct function f_public(){
        local['s_test']={
            'v_test':f_private()+9876
        };
        return local['s_test'];
    }
}

 

Then a simple page that calls the component itself...

 

<cfprocessingdirective pageEncoding="utf-8">
<cfscript>
    variables['c_test']=createObject('component','path.to.cfcFile');
    variables['s_test']=variables['c_test']['f_public']();
    writeDump(var=variables);
</cfscript>

 

Testing the cfc calling, it generates an error:

Variable F_PRIVATE is undefined.
 
 
The error occurred in C:/Websites/test.lab/wwwroot/path/to/_cfcFile.cfc: line 8
6 : 	public struct function f_public(){
7 : 		local['s_test']={
8 : 			'v_test':f_private()+9876
9 : 		};
10 : 		return local['s_test'];
    This topic is closed to new replies. Start a new post to keep the conversation going.
    BKBK
    BKBKCorrect answer
    Community Expert
    Sep 20, 2021 8:14 AM UTC

    I don't think the problem is with the component. I think the problem is this line:

         variables['s_test']=variables['c_test']['f_public']();

     

    The right-hand-side is not quite correct. It does not invoke the function properly. The way it now reads, the function is variables.c_test.f_public, which is not entirely correct.

     

    Correct is:

       variables['s_test']=variables['c_test'].f_public();

     

    10 replies

    Charlie Arehart
    Community Expert
    Community Expert
    Sep 24, 2021 8:36 PM UTC

    @I.am.Sceiffer, I think you've misunderstood the intention in my reply. I was simply pointing out that since you feel your problem worked BEFORE Cf2021, then you should file a bug report. That's how Adobe would know some that worked now is broken. 

     

    The rest of what you said in reply to me suggests you didn't understand why I said this. I'll leave you and others to debate/consider the rest of your points.

     

    As always, I was just trying to help. 

    Translate
    /Charlie (troubleshooter, carehart. org)
    I.am.Sceiffer
    Participating Frequently
    Sep 19, 2021 10:52 PM UTC

    correcting...

     

    "...the same problem comes back!"

    Translate
    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    Sep 20, 2021 8:14 AM UTC

    I don't think the problem is with the component. I think the problem is this line:

         variables['s_test']=variables['c_test']['f_public']();

     

    The right-hand-side is not quite correct. It does not invoke the function properly. The way it now reads, the function is variables.c_test.f_public, which is not entirely correct.

     

    Correct is:

       variables['s_test']=variables['c_test'].f_public();

     

    Translate
    I.am.Sceiffer
    Participating Frequently
    Sep 22, 2021 9:06 AM UTC

    Greatful! Now it's working perfectly! Although I'm asking: why the platform found the function (as a variable) but not the embedded function?

    Continuing to my analysis, JavaScript is years beyond CFscript when I mention "variable callings by bracket notations". Unfortunately... And I use bracket notations to force case sensitivity when I need to track other bug issues.

     

    Thanks for your return and best regards!

    Translate