I'm just stretching my legs, trying to accumulate some techniques that may or may not prove useful someday. I bumped into a way for private functions to be publicly available and I can think of a couple uses (which may or may not be useful), but before I go and try them out I wanted to see if this is a designed "feature" and likely to stick around in future versions, or a bug likely to disappear.


The cfc code:

<cfcomponent>
  <cfscript>
    Variables.foo = "private";
    This.foo2     = "public";
    This.bam      = Variables.bam;
  </cfscript>

  <cffunction name="bar" access="public">
    <cfreturn "bar has returned" />
  </cffunction>
  <cffunction name="bam" access="private">
    <cfreturn "bam has returned" />
  </cffunction>
  <cffunction name="delete" access="public">
    <cfset StructClear(This) />
    <cfreturn "delete has returned" />
  </cffunction>
</cfcomponent>


I test it out with this:


<cfset Pg = createObject("component", "pub_tests") />
<cfdump var="#Pg#" label="base component" />
<cfdump var="#Pg.bar()#" label="bar()" />
<cfdump var="#Pg.bam()#" label="bam()" />
<cfdump var="#Pg.delete()#" label="delete()" />
<cfdump var="#Pg#" label="base component" />
<cfdump var="#Pg.bar()#" label="bar()" />

The results are:

base component - component tests.Objects.pub_tests
FOO2    public
BAM     
  function bam
  Arguments:    none
  Return Type:  
  Roles:        
  Access:       private
  Output:       Yes
DELETE  
  function delete
  Arguments:    none
  Return Type:  
  Roles:        
  Access:       public
  Output:       Yes
BAR     
  function bar
  Arguments:    none
  Return Type:  
  Roles:        
  Access:       public
  Output:       Yes

bar has returned
bam has returned
delete has returned

...and then a blank dump for Pg and then an error because bar() was deleted.

Anyway, you can see that the function bam() is a private function, but it gets executed as if it were public due to the tunnel I made with This.bam = Variables.bam.

I'm thinking this might be useful in a situation where, say, all object methods are set to private or package to keep out interlopers, and a manager object dynamically chooses what becomes public during instantiation based on some parameter or context. But is would be silly to design such a thing if the next CF release shuts it down...

--

    Ben Curtis
    WebSciences International
    http://www.websciences.org/
    v: 310 478 6648
    f: 310 235 2067







----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.


CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to