bombusbee.com Logo bombusbee.com
Fusebox Migration: From ColdFusion to PHP

November 18, 2001

::: The Basics: setting variables :::
Page 2 of 6 ::: 1 2 3 4 5 6 ::: view printable
ColdFusion puts everything into tags*. You set variables, include other files, and even delimit conditional blocks using tags.

In PHP, tags are left to the HTML. Instead we have to do our coding within script delimiters much like JavaScript or ASP. In PHP, these delimiters look like this:
  
<?php
//code goes in here...
?>


From within those delimiters, however, we can do everything PHP allows. Let's start by setting a variable:

In ColdFusion:
  
<cfset foo="bar">


In PHP:
  
<?php
$foo 
"bar";
?>


You may have noticed the "$" (dollar sign) in front of the variable name. In PHP that is the way the PHP engine differentiates a variable from the rest of the code. There is also a ";" (semicolon) at the end of the line. That tells the PHP engine that this is the end of a line (;-D). This is just like JavaScript, though PHP is a little more strict about the presence of that ";".

In ColdFusion, you can also conditionally set variables using CFParam. Like this:

In ColdFusion:
  
<cfparam name="foo" default="bar">


In PHP:
  
<?php
if(!isset($foo)) { $foo "bar"; }
?>


isset is the equivalent of ColdFusion's IsDefined: it just asks if the variable has been set yet. The "!" (exclamation point) is the equivalent of ColdFusion's NOT operator: it essentially inverts the result of a boolean expression. So the PHP phrase basically says, "if $foo is not set, then set $foo equal to 'bar'.". In ColdFusion, the same can be written this way (and this is also equivalent to CFParam):
  
<cfif NOT IsDefined(foo)>
    <cfset foo="bar">
</cfif>



* Except when using CFScript.

<< Introduction The Basics: including files >>

© 2000-2008 bombusbee.com, all rights reserved


Fusebox inside   Powered by PHP   Powered by MySQL   Powered by Apache   SourceForge: support opensource software

Fusebox: Developing Coldfusion Applications

Discovering Fusebox 3 for ColdFusion

Get the new Fusebox books!