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

November 18, 2001

::: The Basics: miscellaneous :::
Page 4 of 6 ::: 1 2 3 4 5 6 ::: view printable
A couple other essentials to programming Fusebox applications are conditionals like if... then... else or switch... case..., conditional operators, and commenting.

The following are equivalents*:

In ColdFusion:
  
<cfif Len(Trim(foo)) AND foo NEQ "bar">
    <cfoutput>
    A man walks into a #foo#, and says, "Ouch!"
    </cfoutput>
<cfelse>
    <cfset error="Please enter a value for <b>foo</b>, other than 'bar'.">
</cfif>


In PHP:
  
<?php
if(strlen(trim($foo)) && $foo != "bar") {
    print 
"A man walks into a $foo, and says, \"Ouch!\"";
} else {
    
$error "Please enter a value for <b>\$foo</b>, other than 'bar'.";
}
?>


You'll notice the PHP has special characters where the ColdFusion uses words. AND and && are the same, and NEQ and != also match up. There are many of these types of differences in syntax, but I can't possibly cover them all here. Nor would I want to when there is already a fabulous resource available at http://www.php.net/manual/.

A switch block is what we in the Fusebox world call the "Fusebox". Not a big difference there — again just syntax differences:

In ColdFusion:
  
<cfswitch expression="#Fusebox.fuseaction#">
    <cfcase value="main">
        [...]
    </cfcase>
    
    <cfcase value="this,that,other" delimeters=",">
        [...]
    </cfcase>
    
    <cfdefaultcase>
        [...]
    <cfdefaultcase>
</cfswitch>


In PHP:
  
<?php
switch($Fusebox["fuseaction"]) {
    case 
"main":
        [...]
        break;
    
    case 
"this":
    case 
"that":
    case 
"other":
        [...]
        break;
    
    default:
        [...]
        break;
}
?>


Finally, we all know that good programmers comment their code. In ColdFusion, comments look just like they do in HTML, but with one more "-" (hyphen). In PHP there are actually three ways to write comments:

In ColdFusion:
  
<!--- I am a single-line comment --->
<!--- 
but I really
could go on
and on
for a few lines
 --->


In PHP:
  
<?php
//I am a single-line comment

# and I am also a single-line comment

/*
but if I want to
go on for a while
I need to use
a different style
*/
?>


Next, on to the good stuff!


* There are many ways to print the "joke" in the second line of the PHP example. The following are all equivalent:
  
<?php
if(strlen(trim($foo)) && $foo != "bar") {
    echo 
"A man walks into a $foo, and says, \"Ouch!\"";
} else {
    
$error "Please enter a value for <b>\$foo</b>, other than 'bar'.";
}
?>

  
<?php
if(strlen(trim($foo)) && $foo != "bar") {
    print 
'A man walks into a ' .$foo', and says, "Ouch!"';
} else {
    
$error "Please enter a value for <b>\$foo</b>, other than 'bar'.";
}
?>

  
<?php
if(strlen(trim($foo)) && $foo != "bar") {
?>
    A man walks into a <?=$foo?>, and says, "Ouch!"
<?php
} else {
    
$error "Please enter a value for <b>\$foo</b>, other than 'bar'.";
}
?>


<< The Basics: including files Fusebox-Enhanced PHP >>

© 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!