Skip to main content
I.am.Sceiffer
Participating Frequently
September 19, 2021
Answered

the component function with visibility problem persists

  • September 19, 2021
  • 2 replies
  • 559 views

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 has been closed for replies.
    Correct answer BKBK

    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();

     

    2 replies

    Charlie Arehart
    Community Expert
    Community Expert
    September 24, 2021

    @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. 

    /Charlie (troubleshooter, carehart. org)
    I.am.Sceiffer
    Participating Frequently
    September 19, 2021

    correcting...

     

    "...the same problem comes back!"

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    September 20, 2021

    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();

     

    I.am.Sceiffer
    Participating Frequently
    September 22, 2021

    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!