[thelist] PHP to CF: Can you translate these functions?

Judah McAuley judah at wiredotter.com
Fri Jul 9 13:11:47 CDT 2010

On Fri, Jul 9, 2010 at 9:49 AM, Frank Marion <lists at frankmarion.com> wrote:
> I'm currently "translating" a small app from PHP to Coldfusion. I don't know
> PHP, but it's programming, so most of it is figureoutable. I do have a
> couple items that I'm stuck on, since Google returns no meaningful results
> for certain searches. Can someone help me confirm/deny/clarify the
> following?
> Is this true: isset = IsDefined() ?


> Is this true: unset = "make IsDefined("variable and associated value") EQ
> false"  ?

You can't really undefine a variable in CF. You can delete a member
from a struct or an array. The main variable, however, will still be
defined. unset would be closest to <cfset foo = ''>

> Is this true: class _database {...} - <cfcomponent>  ?


> Is this true: .implode = ArrayToList()  ?


> Is this true: @fwrite and @fclose = <cffile action = "write">  ?

Sort of. cffile opens and closes a file stream implicitly. In PHP you
have to explicitly open a handle, read from it, then close it. The
exact equivalent in CF are the cfscript functions FileOpen and

> Is this true: die("something") = something<cfabort>  ?

Yes, though also outputting a message when you abort. so it would be
more like <cfoutput>something</cfoutput><cfabort />

> Inside functions, I'm seeing things like: $this->table = $table
> What does "->" mean? $this->confuses me

That is setting an instance variable in a class/object.  In CF, if you
set a variable at the top of a cfcomponent definition, outside a
function, it will be available publicly when you create the object.
You can either refer to it, inside the component, with the variables.
or this. syntax.

so you'd create a component thusly

<cfcomponent name="foo" output="false">
  <cfset this.myvar = "somevalue" />

  <cffunction name="init" returntype="foo">
     <cfset this.myothervar = "someothervalue" />

Then when you invoked the component, CreateObject("foo").init() you
would be able to dump its variables scope and see the two variables
you set.

> class aclassname extends _database

That is one object extending another through inheritance. That means
that it has access to all the methods that the parent object has
defined. To do it in CF, you use the extends="myotherobject" attribute
on your <cfcomponent> definition. Take a look at the Adobe docs for
what it all means.

> Not sure what extending a class is about or it's CF equivalent. Suggestions?

Hope that helps you out Frank.


More information about the thelist mailing list